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:
local button = script.Parent.ImageButton local debounce = false local browseBuyGUI = game.StarterGui.BrowseBuyGUI local teleGUI = game.StarterGui.TeleportingToDealership local function onButtonActivated() if debounce == false then if browseBuyGUI.Enabled == true then browseBuyGUI.Enabled = false teleGUI.Enabled = false else browseBuyGUI.Enabled = true teleGUI.Enabled = true end debounce = true wait(0.5) debounce = false end end 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?
local button = script.Parent.ImageButton local debounce = false local browseBuyGUI = game.StarterGui.BrowseBuyGUI local teleGUI = game.StarterGui.TeleportingToDealership local function onButtonActivated() if debounce == false then if browseBuyGUI.Enabled == true then browseBuyGUI.Enabled = false teleGUI.Enabled = false else browseBuyGUI.Enabled = true teleGUI.Enabled = true end debounce = true wait(0.5) debounce = false end end button.MouseButton1Down:Connect(onButtonActivated)
Don't use 'StarterGui' because its not valid member of player, use 'PlayerGui' Here is the right script:
local player = game.Players.LocalPlayer local button = script.Parent.ImageButton local debounce = true local browseBuyGUI = player.PlayerGui.BrowseBuyGUI local teleGUI = player.PlayerGui.TeleportingToDealership function onButtonActivated() if debounce == false then if browseBuyGUI.Enabled == true then browseBuyGUI.Enabled = false teleGUI.Enabled = false else browseBuyGUI.Enabled = true teleGUI.Enabled = true end debounce = true wait(0.5) debounce = false end end button.Activated:Connect(onButtonActivated)