The button is used to open and close a frame in a Gui. When I click on the button in Studio > Test, it works but, but when I click on the button in server mode, nothing happens...
01 | open = false |
02 | function onClicked() |
03 | if open = = false then |
04 | open = true |
05 | script.Parent:FindFirstChild( "ClickSound" ):Play() |
06 | script.Parent.Parent.ShopGUI.Visible = true |
07 |
08 | else |
09 | open = false |
10 | script.Parent:FindFirstChild( "ClickSound" ):Play() |
11 | script.Parent.Parent.ShopGUI.Visible = false |
12 | end |
13 | end |
14 |
15 | script.Parent.MouseButton 1 Down:connect(onClicked) |
Can someone tell me what I'm doing wrong?
I converted this into local script:
01 | Player = game.Players.LocalPlayer |
02 | function onClicked() |
03 | script.Parent:FindFirstChild( "ClickSound" ):Play() |
04 | if Player.PlayerGui.ScreenGui.ShopGUI.Visible = = false then |
05 | Player.PlayerGui.ScreenGui.ShopGUI.Visible = true |
06 |
07 | elseif Player.PlayerGui.ScreenGui.ShopGUI.Visible = = true then |
08 | Player.PlayerGui.ScreenGui.ShopGUI.Visible = false |
09 | end |
10 | end |
11 |
12 | script.Parent.MouseButton 1 Down:connect(onClicked) |
This should work flawless
01 | local Player = game.Players.LocalPlayer |
02 | local ClickSound = script.Parent:WaitForChild( "ClickSound" ) |
03 | local open = false |
04 | local button = script.Parent |
05 |
06 | button.MouseButton 1 Down:connect( function () |
07 |
08 | if not open then |
09 | open = true |
10 | ClickSound:Play() |
11 | Player.PlayerGui.ScreenGui.ShopGUI.Visible = true |
12 | else |
13 | open = false |
14 | Player.PlayerGui.ScreenGui.ShopGUI.Visible = false |
15 | end |
16 | end ) |