PcoWSkbVqDnWTu_dm2ix
Collapse Sidebar

UDim2

A UDim2 is a type of coordinate used in building user interfaces. It is a combination of two datatype/UDim representing the X and Y dimensions. The most common usages of UDim2s are setting the GuiObject/Size|Size and GuiObject/Position|Position of GuiObjects.

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

Constructors

UDim2.new ( number xScale, number xOffset, number yScale, number yOffset )

Construct a new UDim2 given the coordinates of the two datatype/UDim representing each axis.

UDim2.new ( UDim x, UDim y )

Construct a new UDim2 given two datatype/UDim objects representing the X and Y dimensions, respectively.

UDim2.fromScale ( number xScale, number yScale )

Construct a new UDim2 using the given scalar coordinates. Equivalent to:

UDim2.fromScale(xScale, yScale) == UDim2.new(xScale, 0, yScale, 0)
UDim2.fromOffset ( number xOffset, number yOffset )

Construct a new UDim2 using the given offset coordinates. Equivalent to:

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

Properties

UDim UDim2.X

The x dimension scale and offset

UDim UDim2.Y

The y dimension scale and offset

UDim UDim2.Width

The x dimension scale and offset

UDim UDim2.Height

The y dimension scale and offset

Functions

UDim2 UDim2:Lerp ( UDim2 goal, number alpha )

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

Math Operations

UDim2 UDim2 + UDim2

Returns a UDim2 whose components are the sum of the respective components of the two UDim2s.

UDim2 UDim2 - UDim2

Returns a UDim2 whose components are the difference of the respective components of the two UDim2s.