Hey everyone. It's been a minute since I've coded in roblox studio. I'm trying to make it so a GUI enables and disables on the click of another button but it is failing to work for a reason completely unknown to me. Here is the code:
01 | local button = script.Parent.ImageButton |
02 | local debounce = false |
03 | local browseBuyGUI = game.StarterGui.BrowseBuyGUI |
04 | local teleGUI = game.StarterGui.TeleportingToDealership |
05 | local function onButtonActivated() |
06 | if debounce = = false then |
07 | if browseBuyGUI.Enabled = = true then |
08 | browseBuyGUI.Enabled = false |
09 | teleGUI.Enabled = false |
10 | else |
11 | browseBuyGUI.Enabled = true |
12 | teleGUI.Enabled = true |
13 | end |
14 | debounce = true |
15 | wait( 0.5 ) |
16 | debounce = false |
17 | end |
18 | end |
19 |
20 | button.Activated:Connect(onButtonActivated) |
I have another script set to enable a blur effect whenever the browseBuyGUI is activated, and that works fine. The blur effect appears, but the GUI does not. This is a local script. Here is a picture of the hierarchy. (This same problem also happens with the teleGUI) Any help is appreciated, thanks.
Maybe try using mouse button up and then call the gui when mouse button is up, and then just set the property of the gui in your script to visible or enabled?
01 | local button = script.Parent.ImageButton |
02 | local debounce = false |
03 | local browseBuyGUI = game.StarterGui.BrowseBuyGUI |
04 | local teleGUI = game.StarterGui.TeleportingToDealership |
05 | local function onButtonActivated() |
06 | if debounce = = false then |
07 | if browseBuyGUI.Enabled = = true then |
08 | browseBuyGUI.Enabled = false |
09 | teleGUI.Enabled = false |
10 | else |
11 | browseBuyGUI.Enabled = true |
12 | teleGUI.Enabled = true |
13 | end |
14 | debounce = true |
15 | wait( 0.5 ) |
16 | debounce = false |
17 | end |
18 | end |
19 |
20 | button.MouseButton 1 Down:Connect(onButtonActivated) |
Don't use 'StarterGui' because its not valid member of player, use 'PlayerGui' Here is the right script:
01 | local player = game.Players.LocalPlayer |
02 | local button = script.Parent.ImageButton |
03 | local debounce = true |
04 | local browseBuyGUI = player.PlayerGui.BrowseBuyGUI |
05 | local teleGUI = player.PlayerGui.TeleportingToDealership |
06 |
07 | function onButtonActivated() |
08 | if debounce = = false then |
09 | if browseBuyGUI.Enabled = = true then |
10 | browseBuyGUI.Enabled = false |
11 | teleGUI.Enabled = false |
12 | else |
13 | browseBuyGUI.Enabled = true |
14 | teleGUI.Enabled = true |
15 | end |