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
1 | local gui = game.StarterGui.TutorialGUI.Frame 1 |
2 |
3 | function onTouched(hit) |
4 | if gui.Visible = = false then |
5 | gui.Visible = true |
6 | end |
7 | end |
8 |
9 | script.Parent.Touched:Connect( function () |
Script #2
1 | local gui = game.StarterGui.TutorialGUI.Frame 1 |
2 |
3 | script.Parent.Touched:Connect( function () |
4 | if gui.Visible = = false then |
5 | gui.Visible = true |
6 | end |
7 | end ) |
Your variable 'gui' is holding the Frame1 inside StarterGui, it should rather hold the one inside PlayerGui:
1 | script.Parent.Touched:Connect( function (hit) |
2 | local player = game.Players:GetPlayerFromCharacter(hit.Parent) |
3 | if player then |
4 | local gui = player.PlayerGui:FindFirstChild( "TutorialGUI" ) |
5 | if gui and gui.Frame 1. Visible = = false then |
6 | gui.Frame 1. Visible = true |
7 | end |
8 | end |
9 | 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
1 | script.Parent.Touched:Connect( function (toucher) |
2 | local parent = toucher.Parent |
3 | local player = game.Players:FindFirstChild(parent.Name) |
4 | local gui = player.PlayerGui.TutorialGUI.Frame 1 |
5 | if gui.Visible = = false then |
6 | gui.Visible = true |
7 | end |
8 | end ) |