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

Close/Open GUI script doesn't work?

I have made a script where when you click a button, it toggles the shop GUI on or off, here is the script:

player = game.Players.LocalPlayer
shop = player.PlayerGui:FindFirstChild('ShopGUI').MainFrame
script.Parent.MouseButton1Click:connect(function()
	shop.Visible = not shop.Visible
end)

Any help would be appreciated, thanks! There is also an error when I load up the game on roblox studio, it says: 22:18:54.626 - Players.Player.PlayerGui.Buttons.Frame.TextButton.LocalScript:2: attempt to index a nil value

2 comments

0

The script is a localscript, correct?

0

Yeah, can you put it all into one script?

2 answers

✓ Accepted answer

Two errors:

1: You need to wait for the gui to be out into the player. So:

shop = player.PlayerGui:WaitForChild('ShopGUI').MainFrame -- waits for gui to exist

2. not is an if statement term, it basically means nil. Fixed:

shop.Visible = false -- sets the visible property to false

1 comment

0

Actually, you can use not to negate a bool property value when setting another property. To explain, the Asker is right. You can use obj.Bool = not obj.Bool in order to set the new bool value to the opposite of what it currently is.

The only way it'd error that, while your hierarchy is correct, is if the game is FilteringEnabled. If it is FilteringEnabled, you'll have to access the frame through script.Parent's. Example:

script.Parent.MouseButton1Click:connect(function()
	script.Parent.Parent.Frame.Visible = true
end)

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