#GUI Textlable script help

1 messages · Page 1 of 1 (latest)

hollow junco
#

I'm having some trouble with getting my GUI to show up, basically I'm trying to get the "window" to detect if the player is holding a "brick", if they are then it will unanchor, but if they detect the player is not holding a brick a text will apear alerting the player about it. The window part works fine, but the Textlable wont show up, the script is in a server script which is under the "windowpart1" part in the workspace, thank you!

this is the script:
local windowpart1 = game.Workspace.window.windowpart1
local windowpart2 = game.Workspace.window.windowpart2
local prompt = game.Workspace.window.windowpart1.breakwindow
local brick = game.Workspace.brick
local nobrickgui = game.StarterGui.ScreenGui.nobrickgui

nobrickgui.Visible = false

windowpart1.Anchored = true
windowpart2.Anchored = true

prompt.Triggered:Connect(function(player)
if brick.Parent == player.Character then
windowpart1.Anchored = false
windowpart2.Anchored = false
windowpart1:ApplyImpulse(Vector3.new(25, 0, 0))
windowpart2:ApplyImpulse(Vector3.new(25, 0, 0))
else
nobrickgui.Visible = true
task.wait(3)
nobrickgui.Visible = false
end
end)

brazen pebble
#

The main reason your TextLabel isn't showing up is because you are referencing game.StarterGui.

#

Here is the fixed version with an explanation:

local windowpart2 = game.Workspace.window.windowpart2
local prompt = windowpart1.breakwindow

-- We don't define the GUI here anymore, because we need to find the specific player's GUI later

windowpart1.Anchored = true
windowpart2.Anchored = true

prompt.Triggered:Connect(function(player)
    -- Check if the player is holding the brick
    -- We use FindFirstChild to look for the tool inside the character
    local character = player.Character
    local holdingBrick = character:FindFirstChild("brick") 

    if holdingBrick then
        -- SUCCESS: Break the window
        windowpart1.Anchored = false
        windowpart2.Anchored = false
        
        -- Tip: You might need to set NetworkOwner to the player for smooth physics, 
        -- or just apply impulse on the server like this:
        windowpart1:ApplyImpulse(Vector3.new(25, 0, 0))
        windowpart2:ApplyImpulse(Vector3.new(25, 0, 0))
    else 
        -- FAIL: Show the GUI
        -- 1. Find the PlayerGui inside the specific player who triggered the prompt
        local pGui = player:FindFirstChild("PlayerGui")
        
        if pGui then
            -- 2. Find the ScreenGui and the TextLabel
            -- Make sure the names match exactly what is in your Explorer
            local screenGui = pGui:FindFirstChild("ScreenGui") 
            local nobrickLabel = screenGui and screenGui:FindFirstChild("nobrickgui")
            
            if nobrickLabel then
                nobrickLabel.Visible = true
                task.wait(3)
                nobrickLabel.Visible = false
            end
        end
    end
end)```