Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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:

local button = script.Parent
local frame = script.Parent.Parent.Frame

button.MouseButton1Click:Connect(function()
	if frame.Visible == true then
		frame.Visible = false
	end
	if frame.Visible == false then
		frame.Visible = true 
	end
end)

2 comments

0

Is it a serverscript or localscript?

0

It is an local script

1 answer

✓ Accepted answer

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:

local button = script.Parent
local frame = script.Parent.Parent.Frame

button.MouseButton1Click:Connect(function()

    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.

        frame.Visible = false

    else

        frame.Visible = true

    end

end)

Hope this helped!

1 comment

0

It did!Thanks!

This discussion is preserved as it was. New answers, comments, and votes are closed.