The Create function of
TweenService creates a new
Tween. The function takes three arguments: the object to tween, the
datatype/TweenInfo to use, and a table containing the properties to tween and the values to tween to.
Tweens are used to interpolate the properties of instances. These can be used to create animations for various Roblox objects. Almost any numeric property can be tweened using
The propertyTable parameter that is passed in needs to be a dictionary where the keys are the string names of the property (e.g. “Position”, “Transparency”, “Color”, etc), and the value is the value the property needs to be at the end of the tween. Note that only specific types of properties can be used with
TweenService, but multiple properties can be animated in the same tween. The types of properties that can be tweened are:
Tween created using this function is unique to the object given as the instance parameter. To apply the same tween to another object, call this function again with the new object.
Details on how the interpolation of the tween is to be carried out are given in the
datatype/TweenInfo parameter, such as reversing, looping and easing.
A dictionary of properties, and their target values, to be tweened.
In this example a Tween is created to animate the position and color of a Part. Because the position and color are part of the same tween, they will change at the exact same rate and will reach their goal at the same time.
Looping a Tween
This code sample includes an example of how a looped tween can be created.
A part is instanced in the Workspace, and a Tween is created using TweenService:Create that is set to animate it’s position along the Y axis. The looped effect is achieved by modifying the TweenInfo used in TweenService:Create. Specifically, when RepeatCount is set to be less than 0 the tween will play indefinitely. Also, setting Reverses to true will cause the tween to play in reverse once it has reached it’s destination. In combination this creates a looped effect.
The correct way to make a tween play indefinitely is to set RepeatCount to -1. Developers should avoid using large numbers (or math.huge) as a substitute as this is unstable and may stop working at any point.