Med Written By kitrank

Tween Service Created on: 18-09-2019

How to use TweenService

What's Tween Service?

Tween Service is used for interpolating, or smoothly changing, properties. For example, smoothly changing a part's color into a different color. It can also be used on gui objects to give them animation.

Step 1

Get the service:

local TweenService = game:GetService("TweenService")

Step 2

Defining a variable for TweenInfo, which is a special data type for TweenService, used to configure the animation.

local TweenService = game:GetService("TweenService")

local TI = TweenInfo.new(Time, EasingStyle, EasingDirection, RepeatCount,

Reverseable, Delay) Time = The length of the animation, number value. EasingStyle = The behavior of the animation, Enum.EasingStyle or 0 - 7. • Enum.EasingStyle.Linear or 0 • Enum.EasingStyle.Sine or 1 • Enum.EasingStyle.Back or 2 • Enum.EasingStyle.Quad or 3 • Enum.EasingStyle.Quart or 4 • Enum.EasingStyle.Quint or 5 • Enum.EasingStyle.Bounce or 6 • Enum.EasingStyle.Elastic or 7 EasingDirection = The direction the animation starts, left or right, Enum.EasingDirection or 0 - 2. • Enum.EasingDirection.In or 0 • Enum.EasingDirection.Out or 1 • Enum.EasingDirection.InOut or 2 RepeatCount = How many times the animation will repeat after the initial play, integer value. Reverseable = Whether or not the tween will play in reverse after finishing, true or false value. Delay = Delay before playing the tween for the first time, number value.

Step 3

Defining the properties to be tweened, which is just in a table:

local TweenService = game:GetService("TweenService")

local TI = TweenInfo.new(Time, EasingStyle, EasingDirection, RepeatCount,

Reverseable, Delay)

local TweenProperties = {Transparency = 0.5; Color = Color3.new(1, 0, 0)}
-- These properties are for Tweening a Part.

You can tween any properties that use these values: Number, Bool (true/false), CFrame, Rect, Color3, UDim, UDim2, Vector2, Vector2int16, Vector3.

Step 4

Defining the Tween with the TweenInfo and TweenProperties:, using TweenService:Create():

local TweenService = game:GetService("TweenService")

local TI = TweenInfo.new(1, 0, 1, 0, false, 0)
-- Time:1, EasingStyle:Linear, EasingDirection:In, RepeatCount:0, Reverses:false,
-- Delay:0.

local TweenProperties = {Transparency = 0.5; Color = Color3.new(1, 0, 0}}

local Tween = TweenService:Create(OBJECT, TweenInfo, TweenProperties)

Object is the object you want to tween the properties of. This can be a Part or a gui object, etc.

Step 5

Playing the tween:

local TweenService = game:GetService("TweenService")

local TI = TweenInfo.new(1, 0, 1, 0, false, 0)

local TweenProperties = {Transparency = 0.5; Color = Color3.new(1, 0, 0)}

local Tween = TweenService:Create(workspace.Part, TI, TweenProperties)
-- Will assume that workspace.Part exists, an example part object to tween.

Tween:Play()

The example part will turn 0.5 invisible and turn red within the span of 1 second, the tween's time.

Med Written By kitrank

See kitrank's profile on Roblox

Discussion