Lesson 3
Tweens
Goal: Change a property smoothly over time.
about 6 min3 practice exercises
A tween changes a property smoothly over time. Doors that slide, buttons that grow, lights that fade: all tweens. You do not write a loop. You tell TweenService the goal and it does the steps.
local TweenService = game:GetService("TweenService")
local door = workspace.Door
local info = TweenInfo.new(1, Enum.EasingStyle.Quad, Enum.EasingDirection.Out)
local goal = { Position = door.Position + Vector3.new(0, 8, 0) }
local tween = TweenService:Create(door, info, goal)
tween:Play()
TweenService:Create takes three things: the instance, a TweenInfo and a table of goal values.
TweenInfo.new takes its settings in this order: time in seconds, easing style, easing direction, repeat count, whether it reverses, and a delay before starting. Only the time is needed: TweenInfo.new(5).
You can tween numbers, colors, positions, sizes and CFrames, among others. That covers Transparency, Color, Position, Size and UI properties such as a frame's Position.
Run tweens for visual effects on the client. They look smoother there, and the server has better things to do. The server decides that the door is open. Each client shows it opening.
Try it in Studio
Optional, and the best way to make it stick.
Tween a part's Transparency from 0 to 1 over two seconds, then try Enum.EasingStyle.Bounce.
Sources
Checked against Roblox's documentation on . The lesson is in our own words; these pages are the source of truth.