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

How do I make it so my GUIs enable whenever I call it in a script?

Asked by 4 years ago

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.

0
Is this a tool? Why are you using activated. Thats a value on tools. voidofdeathfire 148 — 4y
0
don't use StarterGui the StarterGui is not for player, use PlayerGui example, game.Players.LocalPlayer.PlayerGui G2001H 75 — 4y

3 answers

Log in to vote
0
Answered by 4 years ago

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?

0
This doesn't work. Mainly because mousebutton1up is different from mousebutton1down. Mousebutton1up is on release and mousebutton1down is when its clicked. voidofdeathfire 148 — 4y
Ad
Log in to vote
0
Answered by 4 years ago
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)
Log in to vote
0
Answered by
G2001H 75
4 years ago

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)

Answer this question