Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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

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)

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)

This discussion is preserved as it was. New answers, comments, and votes are closed.