Skip to main content

tween

An incredibly simple library, does not actually provide support for Tween instances, but rather exposes TweenService:GetValue(), a simple function that remaps a number between 0 and 1 based on TweenService interpolation styles.

Here is an example program written using the tween library to tween a GuiObject's position, given a target, duration and easing style/direction.

local tween = require("tween")

local function tweenPosition(object: GuiObject, targetPosition: UDim2, duration: number, easingStyle: Enum.EasingStyle?, easingDirection: Enun.EasingDirection?)
local initialPosition = object.Position
local alpha = 0

repeat
local remappedAlpha = tween:GetValue(alpha, easingStyle, easingDuration)
object.Position = initialPosition:Lerp(targetPosition, remappedAlpha)

local deltaTime = task.wait() / duration
alpha = math.min(alpha + deltaTime, 1)
until alpha == 1

object.Position = targetPosition
end

-- This function *yields* (waits) until the tween completes, if you didn't want it to wait, you could do:
task.spawn(tweenPosition, object, targetPosition, duration, easingStyle, easingDirection)

-- Instead of:
tweenPosition(object, targetPosition, duration, easingStyle, easingDirection)

If you do not wish to grapple directly with the tween library, you can use this module that losely replicates the behaviour of TweenService.