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

Frame wont close! How to fix?

Asked by 8 years ago

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

Log in to vote
0
Answered by
Discern 1007 Moderation Voter
8 years ago

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!

Ad
Log in to vote
0
Answered by 8 years ago

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).

Answer this question