Ad
Log in to vote
0

The frame won't become visible?

Asked by 3 years ago
--// LOCALSCRIPT


--// Variables
local optGui = script.Parent.Frame
local button = script.Parent.TextButton

--// Booleans
on = false

--// Scripting

button.MouseButton1Click:Connect(function()
    if on then
        on = true
        optGui.Visible = true
    end
end)

button.MouseButton1Click:Connect(function()
    if on then
        on = false
        optGui.Visible = false
    end
end)
0
if on == false then? and True that way maybe? skillfulzombie88 28 — 3y

2 answers

Log in to vote
0
Answered by 3 years ago

Hello there. It seems you are having some problems

local on = false

button.MouseButton1Click:Connect(function()
    if on then
        on = true
        optGui.Visible = true
    end
end)

Check line three if on then this fires if on is true. Problem is... local on = false you set the variable to false. So it wouldn't run. Did you also know there's an easier way to invert true/false variables? you can do something like this

local on = false

button.MouseButton1Click:Connect(function()
    on = not on
end)

on = not on this makes on becomes the oppoosite of itself. Get it? Lets say on = true it will turn on into on = false

Ad
Log in to vote
0
Answered by
Ap_inity 112
3 years ago

Your mistake here was you only need one function. Here's an example:

-- removed variables for now

button.MouseButton1Click:Connect(function()
    if on then
        on = true
        optGui.Visible = true
    end
end)

 -- Using two functions result in the two starting once you click.

button.MouseButton1Click:Connect(function()
    if on then
        on = false
        optGui.Visible = false
    end
end)

Instead, use one function with an else variable:

--// LOCALSCRIPT


--// Variables
local optGui = script.Parent.Frame
local button = script.Parent.TextButton

--// Booleans
on = false

--// Scripting

button.MouseButton1Click:Connect(function()
    if on then
        on = true
        optGui.Visible = true
    else -- Right here!
        on = false
        optGui.Visible = false
    end
end)

I hope this helped!

Answer this question