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

Why won't my GUI destroy upon button activation?

Asked by 4 years ago

I'm making a game that has a start menu in it. I want that GUI to disappear upon the player clicking the "Start Game" button, but it currently doesn't do anything when you click the button.

Here's my code:

local button = script.Parent
local toggled = false
local guiObj = ScreenGui 

local function onButtonActivated()
    if toggled == false then
        guiObj:Destroy()
    else
        button.Text = "Start Game"
        toggled = false
    end
end

button.Activated:Connect(onButtonActivated)

Any tips would be appreciated, thanks! :)

0
Use .MouseButton1Click instead of Activated YTRaulByte 389 — 4y
0
So would it be button.MouseButton1Click:Connect(onButtonActivated) instead? Because I tried that and it didn't work. stealthmode642 -2 — 4y
0
You set guiObj equal to ScreenGui when ScreenGui is not declared. oftenz 367 — 4y
0
The original code said "guiObj = nill" but they told me I should make a reference to the ScreenGui because that's where the button is declared. stealthmode642 -2 — 4y

2 answers

Log in to vote
0
Answered by
raid6n 2196 Moderation Voter Community Moderator
4 years ago
local button = script.Parent
local guiObj = game.StarterGui.ScreenGui

button.MouseButton1Click(
    function()
        guiObj:Destroy()
        button.Text = "Start Game"
    end
)

Ad
Log in to vote
0
Answered by 4 years ago
Edited 4 years ago
local button = script.Parent

local guiObj = ScreenGui 

local function onButtonActivated()
    if guiObj.Enabled == false then
        guiObj.Enabled = true
    elseif guiObj.Enabled == true then
        guiObj.Enabled = false
    end
end

button.Activated:Connect(onButtonActivated)

Answer this question