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