Syntax
local tween = TweenService:Create(instance, TweenInfo.new(1), {Transparency = 1})
tween:Play()Examples
Fade a temporary marker
Script in ServerScriptService. The example creates an anchored part, fades it and destroys it only after successful completion. It does not use a per-frame loop.
local TweenService = game:GetService("TweenService")
local marker = Instance.new("Part")
marker.Anchored = true
marker.Position = Vector3.new(0, 5, 0)
marker.Parent = workspace
local tween = TweenService:Create(marker, TweenInfo.new(2), {Transparency = 1})
tween.Completed:Once(function(state)
if state == Enum.PlaybackState.Completed then marker:Destroy() end
end)
tween:Play()Cancel a transition deliberately
Alternative Script in ServerScriptService. Cancel stops this move after roughly half a second. The part stays at its current interpolated position; cancellation does not automatically reset its starting state.
local TweenService = game:GetService("TweenService")
local part = Instance.new("Part")
part.Anchored = true
part.Parent = workspace
local tween = TweenService:Create(part, TweenInfo.new(3), {Position = Vector3.new(0, 15, 0)})
tween.Completed:Once(function(state) print(state.Name) end)
tween:Play()
task.delay(0.5, function() tween:Cancel() end)Best practices
- Keep a reference to an active tween when a new interaction may cancel it.
- Do not use animation completion as proof that a player earned an authoritative reward.
- Choose short, readable transitions; constant movement can make a UI harder to use.
Runtime & versions
Luau host; Roblox engine examples require Roblox Studio. Feature availability depends on the language and runtime version used by your project; consult the official reference below.
Luau documentation