UDim2

Show Deprecated

The UDim2 data type represents a two-dimensional value where each dimension is composed of a relative scale and an absolute offset in pixels. It is a combination of two UDim data types representing the X and Y dimensions. The most common usages for UDim2 are setting the Size and Position of GuiObjects.


local guiObject = script.Parent
guiObject.Size = UDim2.new(0, 300, 1, 0) -- 300 pixels wide; full height of parent
guiObject.Position = UDim2.new(0, 50, 0, 0) -- 50 pixels from the left

Summary

Constructors

Properties

Methods

Math Operations

  • Produces a UDim2 with components that are the sum of the respective components of the two UDim2 objects.

  • Produces a UDim2 with components that are the difference of the respective components of the two UDim2 objects.

Constructors

new

Returns a new UDim2 with the coordinates of two zero UDim components representing each axis.

new

Returns a new UDim2 given the coordinates of the two UDim components representing each axis.

Parameters

xScale: number

The X dimension scale.

Default Value: 0
xOffset: number

The X dimension offset.

Default Value: 0
yScale: number

The Y dimension scale.

Default Value: 0
yOffset: number

The Y dimension offset.

Default Value: 0

new

Returns a new UDim2 from the given UDim objects representing the X and Y dimensions, respectively.

Parameters

x: UDim
y: UDim

fromScale

Returns a new UDim2 with the given scalar coordinates and no offsets. Equivalent to:


UDim2.fromScale(xScale, yScale) == UDim2.new(xScale, 0, yScale, 0)

Parameters

xScale: number
Default Value: 0
yScale: number
Default Value: 0

fromOffset

Returns a new UDim2 with the given offset coordinates and no scaling. Equivalent to:


UDim2.fromOffset(xOffset, yOffset) == UDim2.new(0, xOffset, 0, yOffset)

Parameters

xOffset: number
Default Value: 0
yOffset: number
Default Value: 0

Properties

The X dimension scale and offset of the UDim2.

The Y dimension scale and offset of the UDim2.

Width

The X dimension scale and offset of the UDim2.

Height

The Y dimension scale and offset of the UDim2.

Methods

Lerp

Returns a UDim2 interpolated linearly between this UDim2 and the given goal. The alpha value should be a number between 0 and 1.

Parameters

goal: UDim2
alpha: number

Returns

Math Operations


Produces a UDim2 with components that are the sum of the respective components of the two UDim2 objects.


Produces a UDim2 with components that are the difference of the respective components of the two UDim2 objects.