Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

✓ Accepted answer

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

1 comment

0

I suggest exploring all the parameters with :Tweening, you can make some cool effects with them.

Random idea - add an if statement with a debounce .

This discussion is preserved as it was. New answers, comments, and votes are closed.