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

Gui only working in studio? [CLOSED]

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)

4 comments

0

Is the game FilteringEnabled, and if so is this a LocalScript?

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

0

So would I say local = script.Parent:WaitForChild("Frame")?

0

Thanks for helping me fix it!

1 answer

✓ Accepted answer

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.

1 comment

0

It works! Thanks!

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