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

How to use TweenPosition with wait()?

Asked by 9 years ago
infobutton.MouseButton1Down:connect(function(open)
    if infoframe.Position == UDim2.new(0, -200, 0.4, 40) then
        infoframe:TweenPosition(UDim2.new(0, -200, 0.4, 40), "Out", "Quad", 1, false)
        infoframe:TweenPosition(UDim2.new(0, 0, 0.4, 40), "Out", "Quad", 1, false)
    else
        infoframe:TweenPosition(UDim2.new(0, 0, 0.4, 40), "Out", "Quad", 1, false)
        infoframe:TweenPosition(UDim2.new(0, -200, 0.4, 40), "Out", "Quad", 1, false)
    end
end)

How come the above won't work, but the below will? It shouldnt need a wait to it, and it wont work with a wait()

infobutton.MouseButton1Down:connect(function(open)
    if infoframe.Position == UDim2.new(0, -200, 0.4, 40) then
        infoframe:TweenPosition(UDim2.new(0, -200, 0.4, 40), "Out", "Quad", 1, false)
        wait(1.5)
        infoframe:TweenPosition(UDim2.new(0, 0, 0.4, 40), "Out", "Quad", 1, false)
    else
        infoframe:TweenPosition(UDim2.new(0, 0, 0.4, 40), "Out", "Quad", 1, false)
        wait(1.5)
        infoframe:TweenPosition(UDim2.new(0, -200, 0.4, 40), "Out", "Quad", 1, false)
    end
end)

1 answer

Log in to vote
2
Answered by 9 years ago

With tweening, the last parameter is an override. If it is set to false, the gui cannot move or be resized again until it is done which will require a wait. Setting the override to false will require a wait, setting it to true will make the gui move slightly to the first desired position but then it will quickly change direction to the second position. Sadly, you have to include a wait if you want it to work correctly. You need to wait a minimum of how long it takes to tween to the new position. I added in an extra wait() just in case.

Also, "Quad" may not be the right type of tween that you would want. There isn't much difference between "Quad" and "Linear", but "Linear" will cause the gui to go straight to the coordinates without slowing down or stopping.

infobutton.MouseButton1Down:connect(function(open)
    if infoframe.Position == UDim2.new(0, -200, 0.4, 40) then
        infoframe:TweenPosition(UDim2.new(0, -200, 0.4, 40), "Out", "Linear", 1, false)
    wait(1)
    wait()
        infoframe:TweenPosition(UDim2.new(0, 0, 0.4, 40), "Out", "Linear", 1, false)
    else
        infoframe:TweenPosition(UDim2.new(0, 0, 0.4, 40), "Out", "Linear", 1, false)
    wait(1)
    wait()
        infoframe:TweenPosition(UDim2.new(0, -200, 0.4, 40), "Out", "Linear", 1, false)
    end
end)

Ad

Answer this question