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

Why isnt my button changing the visibility?

Asked by 5 years ago

Hello I have a function here that opens a window perfectly fine and every click on the button checks to see if the window is open/closed. But when the window is open another click of the button will not close it.

local function openChar()
    if isCharOpen == false then
        script.Parent.RoundBoxChar.Visible = true
        script.Parent.upTriangleChar.Visible = true
        isCharOpen = true
    else
        script.Parent.RoundBoxChar.Visible = false
        script.Parent.upTriangleChar.Visible = false
        isCharOpen = false
    end

1 answer

Log in to vote
1
Answered by
Nowaha 459 Moderation Voter
5 years ago
Edited 5 years ago

Your issue might be the scope of isCharOpen. I'm also not sure if you forgot a part of your code or don't have your function closed, but it's fixed below. Putting a local isCharOpen = false ABOVE the function, in the global scope should fix the issue.

local isCharOpen = false

local function openChar()
    if not isCharOpen then
        script.Parent.RoundBoxChar.Visible = true
        script.Parent.upTriangleChar.Visible = true
        isCharOpen = true
    else
        script.Parent.RoundBoxChar.Visible = false
        script.Parent.upTriangleChar.Visible = false
        isCharOpen = false
    end
end
Ad

Answer this question