> For the complete documentation index, see [llms.txt](https://docs.overdare.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.overdare.com/development/api-reference/classes/tweenservice.md).

# TweenService

TweenService : `Instance`

## Overview

TweenService allows the creation of tween Objects for animation effects

The functionality of a tween depends on the properties set during its creation.

<table><thead><tr><th width="180.6666259765625">DataType</th><th>Usage Example</th></tr></thead><tbody><tr><td>CFrame</td><td>CFrame</td></tr><tr><td>Vector3</td><td>Position, Orientation, Size</td></tr><tr><td>Color3</td><td>Color</td></tr><tr><td>number</td><td>Transparency</td></tr><tr><td>bool</td><td>CanCollide</td></tr><tr><td>UDim2</td><td>Position, Size</td></tr><tr><td>UDim</td><td>Padding</td></tr><tr><td>Vector2</td><td>ImageRectOffset</td></tr><tr><td>Rect</td><td>SliceCenter</td></tr></tbody></table>

**Important Notes**

* Only the types in the table above can be tweened. If a property of another type, such as Enum, string, or Instance, is specified, an error occurs when Create() is called.
* If a new tween targeting the same property as a tween playing on the same instance is played, the existing tween is canceled entirely and its Completed event fires with the Cancelled state.

## Properties

## Methods

### Create

Creates a new tween animation for a specific instance. Arguments passed to the Create() method define the instance to apply the tween to, the TweenInfo defining the tween's behavior, and the properties apply tween to.

#### Parameters

| `Instance` Instance   | The target tween Object                                                  |
| --------------------- | ------------------------------------------------------------------------ |
| `TweenInfo` TweenInfo | An Object that sets the duration, EasingStyle, and repeat count of tween |
| `Value` PropertyTable | A dictionary defining the properties and target values to apply tween to |

#### Return

| `Instance` | The created tween Object |
| ---------- | ------------------------ |

#### Code Samples

```lua
local TweenService = game:GetService("TweenService")
local Part = script.Parent

-- Setting Tween information
local TweenInfoData = TweenInfo.new(
    5,                         -- Time
    Enum.EasingStyle.Linear,   -- EasingStyle
    Enum.EasingDirection.Out,  -- EasingDirection
    0,                         -- Number of repetitions (-1 for infinite)
    false,                     -- Reverses
    0                          -- DelayTime
)

-- Properties to be changed with the tween
local TweenGoals =
{
    Position = Vector3.new(-400, 50, -350)
}

local Tween = TweenService:Create(Part, TweenInfoData, TweenGoals)
Tween:Play()
```

### GetValue

A method that calculates and returns the value obtained by applying EasingStyle and EasingDirection to a progress (alpha) between 0 and 1.

It can be used when you only need the value of an easing curve without creating a Tween. alpha is limited to between 0 and 1.

#### Parameters

| `number` alpha                         | The progress between 0 and 1.  |
| -------------------------------------- | ------------------------------ |
| `Enum.EasingStyle` easingStyle         | The easing style to apply.     |
| `Enum.EasingDirection` easingDirection | The easing direction to apply. |

#### Return

| `number` | The value with easing applied. |
| -------- | ------------------------------ |

#### Code Samples

```lua
local TweenService = game:GetService("TweenService")

local Alpha = 0.5
local EasingStyle = Enum.EasingStyle.Sine
local EasingDirection = Enum.EasingDirection.Out
local Value = TweenService:GetValue(Alpha, EasingStyle, EasingDirection)
print(Value)
```

### SmoothDamp

A method that calculates and returns the next value and velocity so that the current value smoothly follows the target value.

By calling it every frame and passing the returned velocity back into the next call, you can create movement that follows naturally even when the target value keeps changing. The number, Vector2, Vector3, and CFrame types can be used, and current, target, and velocity must be of the same type.

#### Parameters

| `Variant` current   | The current value.                                                     |
| ------------------- | ---------------------------------------------------------------------- |
| `Variant` target    | The target value.                                                      |
| `Variant` velocity  | The current velocity. On the first call, pass a value equivalent to 0. |
| `number` smoothTime | The approximate time (in seconds) it takes to reach the target.        |
| `number` maxSpeed   | The maximum speed.                                                     |
| `number` deltaTime  | The time (in seconds) elapsed since the previous call.                 |

#### Return

| `Tuple` | The next value and the velocity to pass to the next call. |
| ------- | --------------------------------------------------------- |

#### Code Samples

```lua
local RunService = game:GetService("RunService")
local TweenService = game:GetService("TweenService")
local ScreenGui = script.Parent
local Frame = ScreenGui:WaitForChild("Frame")

local CurrentX = 0
local VelocityX = 0
local TargetX = 400
local SmoothTime = 0.3
local MaxSpeed = 10000

local function OnHeartbeat(deltaTime)
    CurrentX, VelocityX = TweenService:SmoothDamp(CurrentX, TargetX, VelocityX, SmoothTime, MaxSpeed, deltaTime)
    Frame.Position = UDim2.new(0, CurrentX, 0, 100)
end
RunService.Heartbeat:Connect(OnHeartbeat)
```

## Events

## See also

{% content-ref url="/pages/4JBNRup7TObw0lJtb37Y" %}
[Tween](/manual/script-manual/advanced-gameplay-systems/tween.md)
{% endcontent-ref %}
