PcoWSkbVqDnWTu_dm2ix
Collapse Sidebar

Completed

The Completed event of a Tween fires when the tween finishes playing. This will happen either when the tween naturally finishes playing, or if it is stopped with TweenBase/Cancel.

A function connected to this event will be passed the PlaybackState of the tween when it finished to give indication about why the tween ended. If the tween finishes naturally the status will be Completed, if cancelled then the state will be Cancelled. Note that calling TweenBase/Pause will not fire the Completed event.

Parameters

Name Type Default Description

The Enum/PlaybackState of the tween upon completion.


Code Samples


Tween Completed

In this example the walkspeed of any player joining the game will be slowed to 0 over 10 seconds using a Tween. The Completed event is used to reset the walkspeed after the Tween has finished playing.


Verifying a Tween has Completed

This code sample includes an example of how Tween.Completed can be used to determine if a Tween has been successfully completed, or cancelled.

In this case a part is instanced and tweened towards 0, 0, 0. Once the tween has completed, if the final PlaybackState is Completed then the part will explode. Were the tween to be cancelled prior to completion, the explosion would not be created.

This method can be used to link tweens to other effects, or even chain several tweens to play after each other.


Tween Conflict

This code sample includes a demonstration of tween conflict. A part is instanced in the Workspace, and two tweens are created that attempt to move the part in conflicting directions.

When both tweens are played, the first tween is cancelled and overwritten by the second tween. This can be seen as the part moves along the Y axis as opposed to the Z axis.

To further demonstrate this, connections have been made for both tweens to the Tween.Completed event. Upon playing the tweens, the following is printed.

tween1: Enum.PlaybackState.Cancelled
tween2: Enum.PlaybackState.Completed

These prints show that the first tween was cancelled (firing the Completed event) immediately upon the second tween being played. The second tween then went on to play until completion.