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:
01 | local button = script.Parent |
02 | local frame = script.Parent.Parent.Frame |
03 |
04 | button.MouseButton 1 Click: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 |
11 | end ) |
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:
01 | local button = script.Parent |
02 | local frame = script.Parent.Parent.Frame |
03 |
04 | button.MouseButton 1 Click: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 |
16 | end ) |
Hope this helped!