Class
TweenService
NotCreatableService
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#
| Create | Creates a new Tween given the object whose properties are to be
tweened, a TweenInfo, and a dictionary of goal property values. |
| GetValue | Calculates a new alpha given an EasingStyle and
EasingDirection.Safe |
| SmoothDamp | Smoothly 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.
| Name | Type | Default | Description |
|---|---|---|---|
instance | Instance | The Instance whose properties are to be tweened. | |
tweenInfo | TweenInfo | The TweenInfo to be used. | |
propertyTable | Dictionary | A dictionary of properties, and their target values, to be tweened. |
Returns
Tween— The newly createdTweenconfigured to interpolate the given properties toward their target values. CallTweenBase: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.
| Name | Type | Default | Description |
|---|---|---|---|
alpha | float | An interpolation value between 0 and 1. | |
easingStyle | EasingStyle | The easing style to use. | |
easingDirection | EasingDirection | The 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.
| Name | Type | Default | Description |
|---|---|---|---|
current | Variant | The current value to smooth. | |
target | Variant | The target value to reach. | |
velocity | Variant | The 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. | |
smoothTime | float | The 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. | |
maxSpeed | float? | 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. | |
dt | float? | 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
Properties (10)
Archivable, archivable, Capabilities, IsInSandbox, Name, Parent, PredictionMode, RobloxLocked, Sandboxed, UniqueId
Methods (39)
AddTag, children, ClearAllChildren, Clone, clone, Destroy, destroy, FindFirstAncestor, FindFirstAncestorOfClass, FindFirstAncestorWhichIsA, FindFirstChild, findFirstChild, FindFirstChildOfClass, FindFirstChildWhichIsA, FindFirstDescendant, GetActor, GetAttribute, GetAttributeChangedSignal, GetAttributes, GetChildren, getChildren, GetDebugId, GetDescendants, GetFullName, GetStyled, GetStyledPropertyChangedSignal, GetTags, HasTag, IsAncestorOf, IsDescendantOf, isDescendantOf, IsPropertyModified, QueryDescendants, Remove, remove, RemoveTag, ResetPropertyToDefault, SetAttribute, WaitForChild