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

Why doesn't my GUI pop up from a Touched Script?

I want a tutorial gui to pop up whenever a player steps on a specific brick. These are the 2 scripts I tried to use. What did I do wrong or what should I modify

Script #1


local gui = game.StarterGui.TutorialGUI.Frame1

function onTouched(hit)
	if gui.Visible == false then
		gui.Visible = true
	end
end

script.Parent.Touched:Connect(function()

Script #2


local gui = game.StarterGui.TutorialGUI.Frame1

script.Parent.Touched:Connect(function()
		if gui.Visible == false then
		gui.Visible = true
	end
end)

2 answers

✓ Accepted answer

Your variable 'gui' is holding the Frame1 inside StarterGui, it should rather hold the one inside PlayerGui:

script.Parent.Touched:Connect(function(hit)
	local player = game.Players:GetPlayerFromCharacter(hit.Parent)
	if player then
		local gui = player.PlayerGui:FindFirstChild("TutorialGUI")
		if gui and gui.Frame1.Visible == false then
			gui.Frame1.Visible = true
		end
	end
end)

Also you have to make sure that what touched your part is a player, otherwise your script will break whenever another random part touches it.

You're trying to edit a gui from StarterGui. All StarterGui does is duplicate anything inside it when a player joins and inserts it into the player's PlayerGui, a folder located inside somebody's Player. To access the PlayerGui, you would have to do something like

script.Parent.Touched:Connect(function(toucher)
	local parent = toucher.Parent
	local player = game.Players:FindFirstChild(parent.Name)
	local gui = player.PlayerGui.TutorialGUI.Frame1
	if gui.Visible == false then
		gui.Visible = true
	end
end)

1 comment

0

Your script works fine until the brick gets touched by something other than a player.

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