Skip to content

Tween

Static Class

This object is a static class. It can be accessed by using its name as a keyword like this: Tween.

Additionally, it cannot be created in the creator menu or with Instance.New().

Tween is a static class used for tweening properties of instances, such as Position, Rotation and Size.

Overlapping Tweens

Multiple tweens can be applied on the same object at the same time, but they must not be tweening the same property. Only the latest tween will override any other one being applied to the property.

All tween methods (eg. TweenColor, TweenNumber, TweenPosition, not Cancel) will return a tweenID in the form of a number used for things like cancelling a tween using the Cancel method.

Methods

TweenColor → int

Parameters

startValue [ Color ]

endValue [ Color ]

time [ float ]

callPerStep [ function ]

type [ TweenType ]

callback [ function ]

Tweens a color between two specified values.

Example

Tween:TweenColor(Color.New(1,1,1,1), Color.New(1,1,1,0), 5, function(val)
    part.Color = val
end, TweenType.linear, function()
    print("Tween finished")
end

TweenNumber → int

Parameters

startValue [ float ]

endValue [ float ]

time [ float ]

callPerStep [ function ]

type [ TweenType ]

callback [ function ]

Tweens a number between two specified values.

Example

Tween:TweenNumber(1, 10, 1, function(val)
    print(val)
end, TweenType.linear, function()
    print("Tween finished")
end)

TweenPosition → int

Parameters

target [ DynamicInstance ]

destination [ Vector3 ]

time [ float ]

type [ TweenType ]

callback [ function ]

Tweens the position of a DynamicInstance

Example

Tween:TweenPosition(part, Vector3.New(100, 0, 0), 100, TweenType.linear, function()
    print("I have arrived!")
end)

TweenRotation → int

Parameters

target [ DynamicInstance ]

destination [ Vector3 ]

time [ float ]

type [ TweenType ]

callback [ function ]

Tweens the rotation of a DynamicInstance

Rotation is in euler angles.

Example

Tween:TweenRotation(part, Vector3.New(0, 90, 0), 1, TweenType.linear, function()
    print("Rotating finished")
end)

TweenSize → int

Parameters

target [ DynamicInstance ]

endValue [ Vector3 ]

time [ float ]

type [ TweenType ]

callback [ function ]

Tweens the size of a DynamicInstance

Example

Tween:TweenSize(part, Vector3.New(5, 5, 5), 1, TweenType.linear, function()
    print("Sizing finished")
end)

TweenVector2 → int

Parameters

startValue [ Vector2 ]

endValue [ Vector2 ]

time [ float ]

callPerStep [ function ]

type [ TweenType ]

callback [ function ]

Tweens a vector2 between two specified values.

Example

Tween:TweenVector2(Vector2.New(0,0), Vector2.New(0,50), 5, function(val)
    UIView.PositionOffset = val
end, TweenType.linear, function()
    print("Tween finished")
end)

TweenVector3 → int

Parameters

startValue [ Vector3 ]

endValue [ Vector3 ]

time [ float ]

callPerStep [ function ]

type [ TweenType ]

callback [ function ]

Tweens a vector3 between two specified values.

Example

Tween:TweenVector3(Vector3.New(0,0,0), Vector3.New(0,50,0), 5, function(val)
    part.Position = val
end, TweenType.linear, function()
    print("Tween finished")
end)

Cancel → void

Parameters: tweenID [ int ]

Cancels an on-going tween based on its tweenID.

local numberTween = Tween:TweenNumber(1, 10, 1, function(val)
    print(val)
end, TweenType.linear, function()
    print("Tween finished")
end)
-- the tweenID is the value of the variable

Tween:Cancel(numberTween)