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)
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)