Skip to content

Tweens

Import Weave.Tween from the Weave module.

1
2
local Weave = require(ReplicatedStorage.Weave)
local Tween = Weave.Tween

Tween values Tween any Weave Value or Computed

local value = Value.new(0)
local tweenInfo = TweenInfo.new(1, Enum.EasingStyle.Linear)

local tweenValue = Tween(value, tweenInfo)

Tween values update automatically

value:set(5)

task.wait(0.5) -- wait half the duration

tweenValue:get() -- 2.5

Tweens follow the value of Weave state using an animation curve.

Image title
A Tween animation curve.

Usage

Call the Tween function with a Weave Value and a TweenInfo

local value = Value.new(0)
local tweenInfo = TweenInfo.new(0.3, Enum.EasingStyle.Quad)

local animated = Tween(value, tweenInfo)

You can :get() its value at any time.

print(animated:get()) --> 0.26425...

TweenInfo can also be a Weave Value or Computed

local goal = Value.new(0)
local tweenInfo = Value.new(TweenInfo.new(0.5, Enum.EasingStyle.Quad))

local animated = Tween(target, tweenInfo)

Tween can transition any number-based Luau type:

local partPosition = Value.new(Vector3.new())

local mousePosition = Value.new(Vector2.new())

local partColor = Value.new(Color3.new(0, 0, 0))

local framePosition = Value.new(UDim2.new(0.5, 0, 0, 0))

local modelPosition = Value.new(CFrame.new())

local tweenInfo = TweenInfo.new(0.5, Enum.EasingStyle.Quad)

local partTween  = Tween(partPosition, tweenInfo)
local mouseTween = Tween(mousePosition, tweenInfo)
local colorTween  = Tween(partPosition, tweenInfo)
local frameTween = Tween(framePosition, tweenInfo)
local modelTween = Tween(modelPosition, tweenInfo)

TweenInfo

Time

The first parameter of TweenInfo is time in seconds.

This specifies how long it will take to animate.

Animation and graph showing varying TweenInfo time. Animation and graph showing varying TweenInfo time.

EasingStyle

The second parameter of TweenInfo is easing style.

Enum.EasingStyle defines the animation curve.

Animation and graph showing some easing styles. Animation and graph showing some easing styles.

Easing Direction

The third parameter of TweenInfo is EasingDirection.

This can be set to:

  • Enum.EasingDirection.Out animates out smoothly.
  • Enum.EasingDirection.In animates in smoothly.
  • Enum.EasingDirection.InOut animates in and out smoothly.

Animation and graph showing some easing directions. Animation and graph showing some easing directions.

Repeats

The fourth parameter of TweenInfo is repeat count.

This can loop the animation a number of times.

Setting the repeat count to a -1 causes it to loop infinitely.

Animation and graph showing various repeat counts. Animation and graph showing various repeat counts.

Reversing

The fifth parameter of TweenInfo is a reversing option.

When enabled, the animation will return to the starting point.

Animation and graph toggling reversing on and off. Animation and graph toggling reversing on and off.

Delay

The sixth and final parameter of TweenInfo is delay.

Increasing this delay adds time before the beginning of the animation curve.

Animation and graph showing varying delay values. Animation and graph showing varying delay values.


Advanced: Interruption

You should avoid interrupting Tweens before they're finished.

Interrupting a tween halfway through leads to abrupt changes in velocity.

Animation and graph showing a tween getting interrupted. Animation and graph showing a tween getting interrupted.

Tweens also can't track constantly changing targets very well.

Animation and graph showing a tween failing to follow a moving target. Animation and graph showing a tween failing to follow a moving target.

These issues arise because tweens don't 'remember' their previous velocity.

To retain velocity, consider using springs, since they can preserve momentum.