Skip to content
Tutorials Center
My learning

Topics

Lesson 24 of 37 ยท Data Stores and Services

TweenService: Smooth Animations for Parts and UI

Animate parts and GUI properties smoothly with TweenService, TweenInfo, easing styles and directions, and understand how a tween interpolates values over time.

If you set a door's Position straight to its open position, the door teleports. That feels cheap. A tween (short for "in-between") moves a property gradually from its current value to a goal over a set time, and the engine calculates every frame for you. Tweens make doors slide, menus fade in, health bars shrink and coins float.

TweenService can animate any property that has a number-like type: Position, Size, Transparency, Color, CFrame, Rotation, and many more. Roblox code is shown read-only; the runnable parts are JavaScript stand-ins that compute the same easing math.

The three ingredients

Every tween needs: an instance, a TweenInfo describing how to move, and a table of goal properties.

LUA
local TweenService = game:GetService("TweenService")

local door = workspace.Door

local info = TweenInfo.new(
	1.5,                          -- Time in seconds
	Enum.EasingStyle.Quad,        -- EasingStyle
	Enum.EasingDirection.Out,     -- EasingDirection
	0,                            -- RepeatCount (0 = play once, -1 = forever)
	false,                        -- Reverses (play backwards after finishing)
	0                             -- DelayTime before starting
)

local goal = { Position = door.Position + Vector3.new(0, 8, 0) }

local tween = TweenService:Create(door, info, goal)
tween:Play()

TweenInfo.new has defaults for everything except time, so TweenInfo.new(1) is a one-second Quad Out tween.

Remember that tweens only change what you list in the goal table. Other properties are untouched.

Controlling a tween

Create returns a Tween object with methods and an event:

LUA
tween:Play()
tween:Pause()
tween:Cancel()

tween.Completed:Connect(function(playbackState)
	if playbackState == Enum.PlaybackState.Completed then
		print("Door fully open")
	end
end)

tween.Completed:Wait() -- pause this script until it finishes

If you tween the same property with two tweens at once, the newest one wins. Cancel the old one first when you restart an animation on a button that can be pressed repeatedly.

Easing styles and directions

Without easing, motion is linear: it starts and stops abruptly at a constant speed. Easing curves make motion feel natural.

  • EasingStyle chooses the curve: Linear, Sine, Quad, Cubic, Quart, Quint, Exponential, Back (overshoots), Bounce, Elastic, and more.
  • EasingDirection chooses where the curve bends: In starts slow and speeds up, Out starts fast and slows down, InOut does both.

For menus and doors, Quad or Cubic with Out is a safe, polished choice. Back makes pop-up windows feel lively, and Bounce suits falling objects.

Easing directions

In Starts slow, ends fast.
Out Starts fast, ends slow.
InOut Slow, fast, then slow.

Out feels natural for things arriving on screen.

1 / 2

Tweening a GUI

The same method animates interfaces. Here a panel slides in from off screen with a fade:

LUA
local panel = script.Parent.Panel
panel.Position = UDim2.fromScale(0.5, 1.5) -- below the screen
panel.BackgroundTransparency = 1

local info = TweenInfo.new(0.4, Enum.EasingStyle.Back, Enum.EasingDirection.Out)
TweenService:Create(panel, info, {
	Position = UDim2.fromScale(0.5, 0.5),
	BackgroundTransparency = 0,
}):Play()

A tween that targets several properties animates them all at the same time with the same timing.

How a tween works

Under the hood each frame computes a progress value from 0 to 1 and then applies an easing function to it. The value is start + (goal - start) * eased(progress). You can reproduce the maths yourself.

JS Easing curves and interpolation (JavaScript stand-in)

Press Run (or Ctrl + Enter) to see the console output here.

No output.

All four curves go from 0 to 100 in one second. QuadIn crawls at first, QuadOut jumps early, and QuadInOut is gentle at both ends.

A tween with a Completed event

The second stand-in includes the full lifecycle: play, per-frame update, and a Completed callback. It uses a fake clock, so the log is deterministic.

JS A tiny TweenService (JavaScript stand-in)

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Notice that both properties finish on the same frame, and the Completed event fires once at the end.

Tips and common mistakes

  • Tweening Anchored parts. Tweens that move parts do not push other objects with physics. For solid, moving platforms, make the part Anchored and tween it.
  • Tweening on the server vs client. A tween on the server replicates every step to all players, which costs bandwidth and looks choppy. For purely visual effects, tween on the client. Use the server only for gameplay that must be authoritative.
  • Restarting a tween. Cancel the old tween first, or store the current one in a variable and check its PlaybackState.
  • Tweening non-numeric properties. Booleans and strings cannot tween. Use Completed or timers for those.
  • Memory. Tween objects are small, but destroy them if you create thousands.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Which three things do you pass to TweenService:Create?

    Create takes the instance to animate, a TweenInfo with timing and easing, and a goal table of final property values.
  2. 2. What does EasingDirection.Out do?

    Out decelerates toward the goal, which feels natural for arriving objects.
  3. 3. How can your script wait until a tween finishes?

    The Completed event fires when the tween ends, so Wait on it pauses until then.
  4. 4. Why should purely visual effects usually be tweened on the client?

    Client-side tweens are smooth and free of network load. Keep the server for changes that gameplay depends on.

Summary

  • A tween moves properties gradually to goal values over a time, with TweenService:Create(instance, tweenInfo, goal) and :Play().
  • TweenInfo sets time, easing style, direction, repeats, reversing and delay.
  • Out easing decelerates, In accelerates, InOut does both; Quad and Cubic are reliable defaults.
  • Use Completed to react when the animation finishes, and cancel old tweens before starting new ones on the same property.
  • Tween visual effects on the client; tween gameplay-critical movement on the server.

Next: DataStores: Saving Data