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

How do I make sure my tweening script doesn't break?

Asked by 8 years ago

OK I just started messing around with tweening on GUI's and so far I've come up with this piece of code:

button = script.Parent.button

button.MouseEnter:connect(function()
    button:TweenPosition(UDim2.new(0, 0, 0, 400))
    print("Enter")
end)

button.MouseLeave:connect(function()
    button:TweenPosition(UDim2.new(0, -85, 0, 400))
    print("Leave")
end)

Generaly, it works. But, if you were to remove your mouse and the gui hasnt finished moving, it breaks and then the script never works again, and the GUI is left at where-ever it broke. So my question is, how do I prevent/fix this?

2 answers

Log in to vote
2
Answered by
EgoMoose 802 Moderation Voter
8 years ago

There's actually a parameter in the TweenPosition method called override. If you set it to true then any current tweens affecting the object will be stopped so that the one just called can run with no obstructions.

For example:

local button = script.Parent

button.MouseEnter:connect(function()
    button:TweenPosition(
        UDim2.new(0, 300, 0, 400), -- position
        1, -- time
        nil, -- easing direction (defaults to out)
        nil, -- easing style (defaults to quad)
        true, -- override variable
        nil -- function you can use to tell if a tween is complete or not
    )
    print("Enter")
end)

button.MouseLeave:connect(function()
    button:TweenPosition(UDim2.new(0, 0, 0, 400), 1, nil, nil, true)
    print("Leave")
end)

More info here: http://wiki.roblox.com/index.php?title=API:Class/GuiObject/TweenPosition

0
I suggest exploring all the parameters with :Tweening, you can make some cool effects with them. PreciseLogic 271 — 8y
Ad
Log in to vote
0
Answered by
3dsonicdx 163
8 years ago

Random idea - add an if statement with a debounce .

Answer this question