If you have ever wanted a door to swing open smoothly instead of snapping into place, or a health bar to drain gradually rather than disappearing in one frame, TweenService is the tool you need. It is a built-in Roblox service that interpolates properties of any Instance from a starting value to an ending value over a set amount of time.
Creating a basic tween
Every tween follows the same three step pattern: get the service, define a TweenInfo, and pass a goal table to
Code: Select all
TweenService:Create()Code: Select all
local TweenService = game:GetService("TweenService")
local part = workspace.Part
local goal = {Position = Vector3.new(10, 5, 0)}
local tweenInfo = TweenInfo.new(2)
local tween = TweenService:Create(part, tweenInfo, goal)
tween:Play()TweenInfo properties
TweenInfo.new() accepts up to six parameters:
- (number, default 1): duration in seconds.
Code: Select all
Time - (Enum.EasingStyle, default Quad): the curve of the motion. Options include Linear, Sine, Back, Bounce, Elastic, and several polynomial variants like Cubic, Quart, and Quint. Each style produces a distinctly different feel.
Code: Select all
EasingStyle - (Enum.EasingDirection, default Out): controls whether the easing is applied forward (In), backward (Out), or both halves (InOut).
Code: Select all
EasingDirection - (number, default 0): how many times the tween repeats. Set to -1 for an infinite loop.
Code: Select all
RepeatCount - (boolean, default false): whether the tween reverses back to the starting value after reaching its goal.
Code: Select all
Reverses - (number, default 0): seconds to wait before the tween begins.
Code: Select all
DelayTime
Code: Select all
local tweenInfo = TweenInfo.new(
2,
Enum.EasingStyle.Sine,
Enum.EasingDirection.InOut,
-1,
true,
0
)The same TweenService works on both 3D world objects and 2D GUI objects, but the properties you target differ.
For 3D parts you typically tween
Code: Select all
CFrameCode: Select all
PositionCode: Select all
ColorCode: Select all
TransparencyCode: Select all
PositionCode: Select all
SizeCode: Select all
RotationCode: Select all
BackgroundTransparencyCode: Select all
TextTransparencyOne UI-specific tip: set
Code: Select all
AnchorPoint = Vector2.new(0.5, 0.5)Code: Select all
GroupTransparencyChaining tweens
The
Code: Select all
CompletedCode: Select all
local positionTween = TweenService:Create(uiObject, tweenInfo, {Position = targetPos})
local rotationTween = TweenService:Create(uiObject, tweenInfo, {Rotation = 45})
positionTween.Completed:Connect(function()
rotationTween:Play()
end)
positionTween:Play()- Smooth doors: tween the CFrame of a door part around a hinge rather than teleporting it. Use EasingStyle.Quad with EasingDirection.Out for a natural swing.
- Camera transitions: tween or
Code: Select all
Camera.CFrameproperties for cinematic pans. Many open cutscene systems chain CFrame tweens with the Completed event to build multi-shot sequences.Code: Select all
CameraType - HUD animations: slide health bars, damage numbers, and minimap panels with UDim2 tweens. A common pattern is tweening from 1 to 0 for a fade-in effect on UI panels.
Code: Select all
BackgroundTransparency - Proximity prompts: tween a button's Position or a part's Color when a player interacts, giving immediate visual feedback.
- Two tweens targeting the same property on the same object will conflict. The newer tween cancels the older one.
- Tween objects are not configurable after creation. If you need different goals, create a new Tween.
- For infinite loops, always use . Do not substitute
Code: Select all
RepeatCount = -1or a large number; the engine treats negative values as the correct loop signal.Code: Select all
math.huge - TweenService operates on a single object. For models with multiple parts, tween each part individually or use a ModelTween approach with .
Code: Select all
SetPrimaryPartCFrame