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

Why is this open/close gui not working? [TWEEN]

Asked by
iWagen 5
6 years ago
Edited 6 years ago

So, I am trying to make a gui open/close with tweening, can someone explain why this is not working? It will open, but it will not close afterwards.

script.Parent.MouseButton1Click:Connect(function()
    local work = false
    if work == false then
        work = true
        script.Parent.Parent:TweenPosition(UDim2.new(0.736, 0,0.304, 0))
        wait(1)
    else
        work = false
        script.Parent.Parent:TweenPosition(UDim2.new(0.932, 0, 0.304, 0))
        wait(1)
    end
end)

This is a local script. Any help will be greatly appreciated.

0
I'm not sure how to explain, I don't have a soltion for you but the "if" never notice that "work" changes value. So it never goes to the "else" Spjureeedd 385 — 6y
0
but it opened after the "if" statement. iWagen 5 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago

Make work a script-wide variable.

The issue here is that your variable, work, is being created from inside the function - and thus is never actually true and not up-to-date with the current state of your UI.

Ad

Answer this question