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

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

Asked by 6 years ago

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

Log in to vote
0
Answered by 6 years ago

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.

Ad
Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

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)
0
Your script works fine until the brick gets touched by something other than a player. Le_Teapots 913 — 6y

Answer this question