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

Close/Open GUI script doesn't work?

Asked by
awfulszn 394 Moderation Voter
8 years ago

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

0
The script is a localscript, correct? shayner32 478 — 8y
0
Yeah, can you put it all into one script? awfulszn 394 — 8y

2 answers

Log in to vote
0
Answered by 8 years ago

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
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. M39a9am3R 3210 — 8y
Ad
Log in to vote
0
Answered by
Shawnyg 4330 Trusted Badge of Merit Snack Break Moderation Voter Community Moderator
8 years ago

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)

Answer this question