Collapse Sidebar


The Cancel function halts playback of its Tween and resets the tween variables. If TweenBase/Play is called again the Tween’s properties will resume interpolating towards their destination but, as the tween variables have been reset, take the full length of the animation to do so.

Only the tween variables are reset, not the properties being changed by the tween. This means if you cancel a tween half way through its animation the properties will not reset to their original values. Where Cancel differs from TweenBase/Pause is that once resumed, it will take the full duration of the tween to complete the animation.


Return Type Summary

Code Samples

Tween Cancel

This sample demonstrates the impact of cancelling a tween.

A part is instanced in the Workspace and a tween is set up to move it along the Y axis. Mid way through the tween, it is cancelled. It can be observed here that the part does not return to its original position, but when it is resumed it takes the full length of the tween (5 seconds) to complete.

This is the key difference TweenBase:Pause() and TweenBase:Cancel().

local TweenService = game:GetService("TweenService")
local part = Instance.new("Part")
part.Position = Vector3.new(0, 10, 0)
part.Anchored = true
part.Parent = game.Workspace
local goal = {}
goal.Position = Vector3.new(0, 50, 0)

local tweenInfo = TweenInfo.new(5)
local tween = TweenService:Create(part, tweenInfo, goal)

local playTick = tick()


local timeTaken = tick() - playTick
print("Tween took "..tostring(timeTaken).." secs to complete")

-- The tween will take 5 seconds to complete as the tween variables have been reset by tween:Cancel()