# Udim2

## Overview

UDim2 is a data type that handles values in both horizontal (X) and vertical (Y) directions. For each direction, it includes both the scale value proportional to the entire size and fixed offset correction value in pixel. It is mostly used when flexibly specifying the size or position of UI elements on the screen.

## Constructors

### new

Creates a single UDim2 object based on the passed scale value for X axis and Y axis, and returns it. The created UDim2 can be used to manually specify the position or size of UI.

#### Parameters

| `number` xScale  | The scale value applied along the X axis relative to the size of parent. |
| ---------------- | ------------------------------------------------------------------------ |
| `number` xOffset | The absolute value applied along the X axis in pixel.                    |
| `number` yScale  | The scale value applied along the Y axis relative to the size of parent. |
| `number` yOffset | The absolute value applied along the Y axis in pixel.                    |

#### Return

| `UDim2` | The UDim2 consisted of the specified scale and offset values. |
| ------- | ------------------------------------------------------------- |

#### Code Samples

```lua
local Position = UDim2.new(0.5, 10, 0.5, 20)

TextLabel.Position = Position
```

## Properties

### X

`UDim`

It represents both the relative scale value and offset value in pixel applied along the X axis.

#### Code Samples

```lua
local Position = UDim2.new(0.5, 10, 0.5, 20)

print(Position.X.Scale, Position.X.Offset)
```

### Y

`UDim`

It represents both the relative scale value and offset value in pixel applied along the Y axis.

#### Code Samples

```lua
local Position = UDim2.new(0.5, 10, 0.5, 20)

print(Position.Y.Scale, Position.Y.Offset)
```

## Methods

### Lerp

Returns a new Dim2 calculated by linearly interpolating between the current Dim2 and the target Dim2 according to the alpha ratio.

#### Parameters

| `UDim2` GoalValue | The target UDim2 to be interpolated.    |
| ----------------- | --------------------------------------- |
| `number` Alpha    | A value indicating interpolation ratio. |

#### Return

| `UDim2` | The created UDim2. |
| ------- | ------------------ |

#### Code Samples

```lua
local a = UDim2.new(0.0, 0, 0.1, 0)
local b = UDim2.new(0.1, 100, 0.1, 100)
print(a:Lerp(b, 0.3)) --> Output: {0.03, 30}, {0.1, 30}
```

## Events

## See also

{% content-ref url="/pages/f7dY0KeRkFsA0mxkM6OB" %}
[Coordinate System](/manual/studio-manual/get-started/coordinate-system.md)
{% endcontent-ref %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.overdare.com/development/api-reference/datatype/udim2.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
