Roblox UtilitiesDevlHub Roblox Documentation

Class

TweenService

NotCreatableService
Inherits
Instance › Object
Memory category
Instances

Used to create Tweens which interpolate, or tween, the properties of instances.

TweenService is used to create Tweens which interpolate, or tween, the properties of instances. Tweens can be used on any object with compatible property types, including:

TweenService:Create(), the primary constructor function, takes TweenInfo specifications about the tween and generates the Tween object which can then be used to play the tween.

Note that Tweens can interpolate multiple properties at the same time, but they must not be interpolating the same property. If two tweens attempt to modify the same property, the initial tween will be cancelled and overwritten by the most recent tween.

Methods 3#

CreateCreates a new Tween given the object whose properties are to be tweened, a TweenInfo, and a dictionary of goal property values.
GetValueCalculates a new alpha given an EasingStyle and EasingDirection.Safe
SmoothDampSmoothly interpolates a value towards a target, simulating a critically damped spring.Safe

Create(instance: Instance, tweenInfo: TweenInfo, propertyTable: Dictionary): Tween#

This constructor creates a new Tween from three arguments: the object to tween, the TweenInfo specifications, and a table containing the properties to tween and values to tween to.

The propertyTable parameter needs to be a dictionary where the keys are the string names of the property (for example Position, Transparency, or Color), and the values are the property targets at the end of the tween.

The 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.

NameTypeDefaultDescription
instanceInstanceThe Instance whose properties are to be tweened.
tweenInfoTweenInfoThe TweenInfo to be used.
propertyTableDictionaryA dictionary of properties, and their target values, to be tweened.
Returns
  • Tween — The newly created Tween configured to interpolate the given properties toward their target values. Call TweenBase:Play() on the returned object to start the tween.

GetValue(alpha: float, easingStyle: EasingStyle, easingDirection: EasingDirection): float#

Safe

Returns a new alpha value for interpolating using the given alpha value, EasingStyle, and EasingDirection. The provided alpha value will be clamped between 0 and 1.

NameTypeDefaultDescription
alphafloatAn interpolation value between 0 and 1.
easingStyleEasingStyleThe easing style to use.
easingDirectionEasingDirectionThe easing direction to use.
Returns
  • float — A new alpha value generated from the given easing style and direction.

SmoothDamp(current: Variant, target: Variant, velocity: Variant, smoothTime: float, maxSpeed: float?, dt: float?): Tuple#

Safe

Smoothly interpolates a value towards a target, simulating a critically damped spring. Returns a tuple with (newValue, newVelocity). newVelocity needs to be fed to the next call of SmoothDamp to ensure smooth results. Supports number, Vector2, Vector3, and CFrame.

NameTypeDefaultDescription
currentVariantThe current value to smooth.
targetVariantThe target value to reach.
velocityVariantThe current velocity with which the current value should approach the target value. You shouldn't modify this value between calls yourself, it's used to store the stateful velocity. In most cases, initialize this with 0, Vector2.zero, Vector3.zero, or CFrame.identity depending on the type, or if needed, with your initial velocity.
smoothTimefloatThe duration over which the total smoothing operation should take place. Note that since this is a damped spring, there's no guarantee current will be exactly target after this time, but it will be close. Smaller values result in quicker smoothing.
maxSpeedfloat?The maximum speed at which the current value should approach the target value. Leaving this nil defaults to math.huge, meaning the velocity isn't clamped.
dtfloat?The rate at which the smoothing operation should be applied. If left nil, the current engine delta time will be used.
Returns
  • Tuple — The new value and new velocity calculated from the smoothing operation.

Inherited members#

Inherited from Instance 58
Inherited from Object 6
Properties (2)

ClassName, className

Events (1)

Changed