Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
2

How do I make a GUI visible when the player touches a block?

Asked by 9 years ago

I know I've done this before, I just forgot how. This is what I tried:

function blind()
    game.StarterGui.ScreenGui.BLIND.Visible = true
end

script.Parent.Touched:connect(blind)

3 answers

Log in to vote
0
Answered by
mine248 40
9 years ago

I know for the seat, don't know about that.

Ad
Log in to vote
0
Answered by 9 years ago

Here, try this one. In order for this to work, the gui can't be visible.

local part = script.Parent -- We declare the part as a variable since it has the script inside


part.Touched:connect(function(plr) -- We connect the part into a function with a parameter 
    local humanoid = plr.Parent:FindFirstChild("Humanoid") -- We are looking for a humanoid since we don't want anything else to touch the part except the player
    if humanoid then -- if there's a humanoid then..
        local name = game.Players:FindFirstChild(plr.Parent.Name) -- We look for the player's name to be sure he/she exists
        name.PlayerGui.ScreenGui.BLIND.Visible = true -- We look inside his/her PlayerGui to make the frame visible to true
    end
end)
Log in to vote
0
Answered by 9 years ago

You are making the one in the StarterGui visible, not the one in PlayerGui.

To get the playerGui do this:

script.Parent.Touched:connect(function(hit)
    if game.Players:FindFirstChild(hit.Parent.Name) then --Make sure that the player exists
        local pl = game.Players:FindFirstChild(script.Touched.Parent.Name) --Get the player
        local plGui = pl:FindFirstChild("PlayerGui") --Find "PlayerGui" in the player
        plGui.ScreenGui.BLIND.Visible = true
    end
end)

Answer this question