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

Why my button doesn't work when i click on it? No problems in output?!What do i do?

Asked by
DashDQ 17
4 years ago
Edited 4 years ago

So basically if i click the button it would show a GUI, but if i click again again on it, it should close the GUI.Ok it shows the GUI only once but if i click again it stays frozen.GUI won't do anything after that.

Here is the script:

01local button = script.Parent
02local frame = script.Parent.Parent.Frame
03 
04button.MouseButton1Click:Connect(function()
05    if frame.Visible == true then
06        frame.Visible = false
07    end
08    if frame.Visible == false then
09        frame.Visible = true
10    end
11end)
0
Is it a serverscript or localscript? Qariter 110 — 4y
0
It is an local script DashDQ 17 — 4y

1 answer

Log in to vote
3
Answered by 4 years ago
Edited 4 years ago

It is because when the luau interpreter is gonna read that script, it is gonna see that the frame.Visible is true, run the statement and turn it false. Then, it is gonna see that frame.Visible is false, and turn it to true. What you should do to avoid this problem is:

01local button = script.Parent
02local frame = script.Parent.Parent.Frame
03 
04button.MouseButton1Click:Connect(function()
05 
06    if frame.Visible == true then -- if this runs, it is gonna turn false and not go through the else, if it doesn't, it is not gonna turn false and go to the else, which is gonna turn it true.
07 
08        frame.Visible = false
09 
10    else
11 
12        frame.Visible = true
13 
14    end
15 
16end)

Hope this helped!

0
It did!Thanks! DashDQ 17 — 4y
Ad

Answer this question