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?
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