Skip to content
Tutorials Center
My learning

Topics

Lesson 18 of 37 ยท Parts, Physics and Building

Tweening and Moving Parts

"Animate parts smoothly with TweenService and TweenInfo: easing styles, repeating and reversing tweens, the Completed event, Heartbeat loops, and moving doors, lifts and platforms."

Setting part.Position jumps a part instantly. Games feel alive when things glide: a door that swings open, a lift that rises, a coin that bobs, a block that fades out. Roblox gives you TweenService for exactly this. A tween smoothly changes properties from their current values to new ones over a given time.

Your first tween

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

local door = workspace.Door      -- an anchored part

local info = TweenInfo.new(2)    -- take 2 seconds
local goals = { Position = door.Position + Vector3.new(0, 10, 0) }

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

Three pieces make a tween:

  1. The target: the instance whose properties will change.
  2. A TweenInfo: how the change should run (time, style, direction, repeats).
  3. A goals table: property names and their final values.

TweenService:Create returns a tween object; nothing happens until you call :Play(). You can tween anything numeric or with a numeric type: Position, Size, Color, Transparency, CFrame, Volume, even UI properties like BackgroundTransparency.

Tween parts that are anchored. If you tween an unanchored part, physics keeps pushing it around while the tween fights back. Tweening a CFrame or Position of an anchored part is the standard way to build moving platforms and doors.

TweenInfo in full

LUA
TweenInfo.new(
	time,             -- seconds
	easingStyle,      -- Enum.EasingStyle
	easingDirection,  -- Enum.EasingDirection
	repeatCount,      -- how many extra times; -1 means forever
	reverses,         -- true to play backward after each pass
	delayTime         -- seconds to wait before starting
)

For example, a lift that rises and falls forever:

LUA
local info = TweenInfo.new(
	3,
	Enum.EasingStyle.Sine,
	Enum.EasingDirection.InOut,
	-1,      -- repeat forever
	true,    -- reverse each time
	0
)
TweenService:Create(lift, info, { Position = lift.Position + Vector3.new(0, 20, 0) }):Play()

Only time is required; the rest have defaults (Quad style, Out direction, no repeat).

Easing styles

An easing style shapes how fast the change goes at each moment. A straight line (Linear) feels robotic; curves feel natural.

Style Feel
Linear Constant speed
Sine, Quad, Cubic, Quart, Quint Increasingly strong ease (Sine is gentlest)
Exponential Very sharp start or end
Back Overshoots, then settles
Bounce Bounces at the end
Elastic Wobbles like a spring

The direction says which end is eased: In (slow start), Out (slow end), InOut (both). Doors and lifts usually look best with Sine or Quad and InOut; pop-up UI loves Back and Out.

Events and control

A tween has a state and a Completed event:

LUA
local tween = TweenService:Create(door, TweenInfo.new(1), { Transparency = 1 })
tween.Completed:Connect(function(playbackState)
	print("Finished with", playbackState)    --> Enum.PlaybackState.Completed
	door:Destroy()
end)
tween:Play()

tween:Pause()
tween:Cancel()     -- stop and leave properties where they are

Or wait for it inline: tween.Completed:Wait(). A tween playing on a property will replace another tween on the same property, so a part never runs two tweens on Position at once.

A touch-activated door

Combine tweens with the Touched lesson:

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

local door = workspace.Door
local closedCFrame = door.CFrame
local openCFrame = closedCFrame * CFrame.new(0, door.Size.Y, 0)   -- slide up by its height

local info = TweenInfo.new(0.6, Enum.EasingStyle.Quad, Enum.EasingDirection.Out)
local openTween = TweenService:Create(door, info, { CFrame = openCFrame })
local closeTween = TweenService:Create(door, info, { CFrame = closedCFrame })

local isOpen = false
workspace.Button.Touched:Connect(function(otherPart)
	if isOpen or not otherPart.Parent:FindFirstChildOfClass("Humanoid") then
		return
	end
	isOpen = true
	openTween:Play()
	task.wait(3)
	closeTween:Play()
	closeTween.Completed:Wait()
	isOpen = false
end)

The isOpen flag is the debounce; the door cannot be triggered again until it has finished closing.

Moving every frame

Sometimes you want a motion no single tween describes: a part that follows a path, a rotating fan, a bobbing coin. Use a per-frame loop on RunService.Heartbeat, which passes the time dt since the last frame:

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

local coin = workspace.Coin
local startCFrame = coin.CFrame
local elapsed = 0

RunService.Heartbeat:Connect(function(dt)
	elapsed += dt
	local bob = math.sin(elapsed * 2) * 1                       -- up and down by 1 stud
	local spin = CFrame.Angles(0, elapsed * math.rad(90), 0)    -- 90 degrees per second
	coin.CFrame = startCFrame * CFrame.new(0, bob, 0) * spin
end)

Multiplying by dt makes the motion frame-rate independent: a player at 30 FPS and one at 144 FPS see the same speed. (A Script on the server only runs Heartbeat at the server's rate; moving lots of decorative objects is better done on each player's client, in a LocalScript, to avoid sending constant updates.)

Lerp: the do-it-yourself tween

Vector3:Lerp(goal, alpha) and CFrame:Lerp(goal, alpha) blend between two values. A tween is just an alpha moving from 0 to 1 over time, with an easing curve applied:

LUA
local start = part.Position
local goal = start + Vector3.new(20, 0, 0)
for alpha = 0, 1, 0.05 do
	part.Position = start:Lerp(goal, alpha)
	task.wait(1 / 30)
end
part.Position = goal

Prefer TweenService for fixed A-to-B motion: it is smoother and cheaper than your own loop.

Stand-in: easing curves

TweenService runs in the engine. The idea inside it is a function that turns time (0 to 1) into progress (0 to 1). This stand-in prints a few easing curves as numbers and as a rough text graph so you can compare Linear, Quad and Back.

JS Stand-in: easing functions (JavaScript)

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

No output.

BackOut goes past 1.00 and returns, which is the overshoot you see with the Back style.

Stand-in: a tween engine

This stand-in is a tiny Tween that does what TweenService:Create(...):Play() does for a number: it moves from the start value to the goal over a duration using an easing function, and calls Completed at the end. Time is simulated in fixed steps so the output is deterministic.

JS Stand-in: Tween from A to B with Completed (JavaScript)

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

No output.

The door moves fast at first and slows near the top, because QuadOut eases the end. Swap in a linear easing t => t to see constant speed.

Choosing the right tool

Task Tool
Move or fade from A to B once TweenService
Loop between two states forever TweenInfo with -1 and true
Continuous motion (spin, bob, orbit) Heartbeat with dt
Physical motion with weight Constraints, forces or velocity
Moving a whole model Tween its PrimaryPart's CFrame or use PivotTo on each step

You have now built, scripted and animated parts. The next chapters add interface, saved data and multiplayer on top of these foundations; the full course outline is on the track page.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What are the three arguments of TweenService:Create?

    Create takes the instance to change, a TweenInfo describing the timing, and a table of goal property values.
  2. 2. What does a repeatCount of -1 in TweenInfo mean?

    -1 repeats the tween forever.
  3. 3. Why multiply movement by dt inside a Heartbeat loop?

    dt is the time since the last frame; scaling by it makes motion frame-rate independent.
  4. 4. Which kind of part should you tween with Position or CFrame?

    Anchored parts are not moved by physics, so the tween has full control.

Summary

  • TweenService:Create(instance, TweenInfo.new(...), goals) then :Play() animates properties smoothly.
  • Easing style and direction shape the motion; Completed fires when it ends; repeat with -1 and true.
  • Use Heartbeat and dt for continuous motion, and Lerp for hand-made blends.
  • Tween anchored parts; combine tweens with Touched for doors, lifts and platforms.

Next: GUI Basics: ScreenGui, Frames, Labels and Buttons