Tween

Show Deprecated

Tweens are used to interpolate the properties of instances. The Tween object itself controls the playback of the interpolation. Creating and configuring tweens is done with the TweenService:Create() function. This is the only way to create tweens. Instance.new cannot be used for this particular object.

Note that while the configuration of a tween can be accessed after a tween has been created, it can not be modified. If new goals are needed for interpolation, a new tween must be created. Further information on how to create Tweens can be found on the TweenService page.

Multiple tweens can be played on the same object at the same time, but they must not be animating 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 (see examples).

Although other methods exist for tweening objects, such as GuiObject:TweenSizeAndPosition(), Tweens allows multiple properties to be modified and for the animation to be paused and cancelled at any point.

Code Samples

Tween Creation

1local TweenService = game:GetService("TweenService")
2
3local part = Instance.new("Part")
4part.Position = Vector3.new(0, 10, 0)
5part.Color = Color3.new(1, 0, 0)
6part.Anchored = true
7part.Parent = game.Workspace
8
9local goal = {}
10goal.Position = Vector3.new(10, 10, 0)
11goal.Color = Color3.new(0, 1, 0)
12
13local tweenInfo = TweenInfo.new(5)
14
15local tween = TweenService:Create(part, tweenInfo, goal)
16
17tween:Play()
Tween Conflict

1local TweenService = game:GetService("TweenService")
2
3local part = Instance.new("Part")
4part.Position = Vector3.new(0, 10, 0)
5part.Anchored = true
6part.Parent = game.Workspace
7
8local tweenInfo = TweenInfo.new(5)
9
10-- create two conflicting tweens (both trying to animate part.Position)
11local tween1 = TweenService:Create(part, tweenInfo, { Position = Vector3.new(0, 10, 20) })
12local tween2 = TweenService:Create(part, tweenInfo, { Position = Vector3.new(0, 30, 0) })
13
14-- listen for their completion status
15tween1.Completed:Connect(function(playbackState)
16 print("tween1: " .. tostring(playbackState))
17end)
18tween2.Completed:Connect(function(playbackState)
19 print("tween2: " .. tostring(playbackState))
20end)
21
22-- try to play them both
23tween1:Play()
24tween2:Play()

Summary

Properties

The read-only Instance property of a Tween points to the Instance whose properties are being interpolated by the tween.

READ ONLY
NOT REPLICATED

Read-only property that includes information on how the interpolation of the Tween is to be carried out, using the TweenInfo data type.

READ ONLY
NOT REPLICATED

Events

Methods

Properties

Instance

Read Only
Not Replicated

The Instance property of a Tween points to the Instance whose properties are being interpolated by the tween. As with all Tween properties, the Instance property is read only. If a developer wants to tween a different instance they must create a new Tween using TweenService:Create().

TweenInfo

Read Only
Not Replicated

Read-only property that includes information on how the interpolation of the Tween is to be carried out, using the TweenInfo data type. The TweenInfo data type includes a range of properties that can be used to achieve various styles of animation, including reversing and looping Tweens (see examples).

As with all Tween properties, the TweenInfo property is read only. If a developer wants to modify the TweenInfo of a Tween they must create a new Tween using TweenService:Create().

Events

Methods