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

Frame wont close! How to fix?

I have a click open/close button that opens a frame. Problem is when you click "Close" the frame dosent close. What is the problem and how to fix it?

Box = script.Parent.Box
Button = script.Parent.Button
Open = false

Button.MouseButton1Down:connect(function(open)
	if Open == false then
		Button.Text = "Close"
		Box.Visible = true
	elseif Open == true then
		Button.Text = "Information"
		Box.Visible = false
	end
end)


Box is the frame, Button is the open/close button

2 answers

✓ Accepted answer

You are not setting your variable Open between true and false. Therefore, the first condition (opening the frame) will always be the one that runs.


Box = script.Parent.Box
Button = script.Parent.Button
Open = false

Button.MouseButton1Down:connect(function()
    if Open == false then
        Button.Text = "Close"
        Box.Visible = true
        Open = true --Set it to true here.
    elseif Open == true then
        Button.Text = "Information"
        Box.Visible = false
        Open = false --Set it to false here.
    end
end)

If I helped you out, be sure to accept my answer!

You don't have to put "Open" in the function perimeters, you are connecting the function with MouseButton1Down. Open is also a global variable so you can use it or change it anywhere (even inside functions).

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