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

Why isn't my LOCAL script that toggles a gui on/off working?

Asked by
NSMascot 113
4 years ago

i'm making a gui that when you click a button it toggles another section of the gui on/off. here is the script

function leftClick(mouse)
    if script.Parent.Parent.DripColors.Visible == true then
        script.Parent.Parent.DripColors.Visible = false
    else
        script.Parent.Parent.DripColors.Visible = true
end
script.Parent.MouseButton1Click:connect(leftClick)
end

1). all the locations are correct 2). I've tried using :WaitForChild() 3). I've Looked on the internet everywhere for the answer 4). Now i am asking this website 5). Please Help

1 answer

Log in to vote
2
Answered by
sleazel 1287 Moderation Voter
4 years ago

Seems like a silly mistake. Your event connection is declared inside the function. Function never runs, so the connection is never made. Please correct:

function leftClick(mouse)

    if script.Parent.Parent.DripColors.Visible == true then
        script.Parent.Parent.DripColors.Visible = false
    else
        script.Parent.Parent.DripColors.Visible = true
    end

end
--here this line needs to be outside function
script.Parent.MouseButton1Click:connect(leftClick)

I hope I helped.

0
Thankyou NSMascot 113 — 4y
Ad

Answer this question