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

Gui only working in studio? [CLOSED]

Asked by 8 years ago
Edited 8 years ago

So I made a script for a gui so when MouseButton1Down:connect the GUI would open. It opens and closes in studio but when I go to the game, the GUI does not open or close. Did I do something wrong?

Frame = script.Parent.Frame
Button = script.Parent.TextButton
Open =  false

Button.MouseButton1Down:connect(function(open)
    if Open == false then
        Frame.Visible = true
        Open = true
    elseif Open == true then
        Frame.Visible = false
        Open = false
    end
end)
0
Is the game FilteringEnabled, and if so is this a LocalScript? M39a9am3R 3210 — 8y
0
The reason this won't work is because the script runs before the gui is fully loaded. Change the locals to script.Parent:WaitForChild("Frame") TheDeadlyPanther 2460 — 8y
0
So would I say local = script.Parent:WaitForChild("Frame")? BunnyFilms1 297 — 8y
0
Thanks for helping me fix it! BunnyFilms1 297 — 8y

1 answer

Log in to vote
0
Answered by 8 years ago

This is most likely the fact that the script is running before the character loads, therefore the script cannot find the object it's referring to. A simple solution is adding some WaitForChild's to the beginning of the script.

-- Checking for all the loaded elements.
script.Parent:WaitForChild("Frame")
script.Parent:WaitForChild("TextButton")
-- Check Complete.
Frame = script.Parent.Frame
Button = script.Parent.TextButton
Open =  false

Button.MouseButton1Down:connect(function(open)
    if Open == false then
        Frame.Visible = true
        Open = true
    elseif Open == true then
        Frame.Visible = false
        Open = false
    end
end)

Tell me if this doesn't work.

0
It works! Thanks! BunnyFilms1 297 — 8y
Ad

Answer this question