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

OpenClose a gui TextButton is not working in game, but it works in studio?

I have made an Open/Close a GUI button for my Shop GUI. For some reason, when I click the button in studio it opens the frame. In-game and in team test it does not. Please help. This is the code I used:

local Button = script.Parent
Box = script.Parent.Parent.ScrollingFrame

function onClick()
	if Box.Visible == false then
		Box.Visible = true
	elseif Box.Visible == true then
		Box.Visible = false
	end
end

Button.MouseButton1Click:connect(onClick)

3 comments

0

is this in a server script?

0

It is in a regular script inside a TextButton.

0

Put it in a localscript

2 answers

✓ Accepted answer

Since it turns visible in studio but not in game, that means you're most likely using a script for this. Scripts can't run in the PlayerGui, so you'll have to use a localscript.

local Box = script.Parent.Parent:WaitForChild(”ScrollingFrame”) As things may not have loaded yet, the script will be broken, you should almost always use WaitForChild(), and second, this will only work in a local script as a ServerScript cant access the playergui

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