Skip to content

Data type

UDim2

Official docs ↗

Represents a two-dimensional value where each dimension is composed of a relative scale and an absolute offset.

About UDim2

The UDim2 data type represents a two-dimensional value where each dimension is composed of a relative scale and an absolute offset in logical 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 = Instance.new("Frame")
guiObject.Size = UDim2.new(0, 300, 1, 0)  -- 300 logical pixels wide; full height of parent
guiObject.Position = UDim2.new(0, 50, 0, 0)  -- 50 logical pixels from the left
print(guiObject.Size) --> {0, 300}, {1, 0}

Constructors 5

  • UDim2.new()Returns a new UDim2 with the coordinates of two zero UDim components representing each axis.
  • UDim2.new(xScale: number = 0, xOffset: number = 0, yScale: number = 0, yOffset: number = 0)Returns a new UDim2 given the coordinates of the two UDim components representing each axis.
  • UDim2.new(x: UDim, y: UDim)Returns a new UDim2 from the given UDim objects representing the X and Y dimensions, respectively.
  • UDim2.fromScale(xScale: number = 0, yScale: number = 0)Returns a new UDim2 with the given scale components and no offsets.
  • UDim2.fromOffset(xOffset: number = 0, yOffset: number = 0)Returns a new UDim2 with the given offset components and no scaling.

Properties 4

  • X: UDimThe X dimension scale and offset of the UDim2.

    The UDim component for the horizontal axis. The returned UDim has a .Scale (relative fraction) and .Offset (absolute logical pixels). This property is equivalent to UDim2.Width.

    local pos = UDim2.new(0.5, 10, 1, 0)
    print(pos.X.Scale)   -- 0.5
    print(pos.X.Offset)  -- 10
    
  • Y: UDimThe Y dimension scale and offset of the UDim2.

    The UDim component for the vertical axis. The returned UDim has a .Scale (relative fraction) and .Offset (absolute logical pixels). This property is equivalent to UDim2.Height.

    local pos = UDim2.new(0.5, 10, 1, 0)
    print(pos.Y.Scale)   -- 1
    print(pos.Y.Offset)  -- 0
    
  • Width: UDimThe X dimension scale and offset of the UDim2.

    A synonym for UDim2.X. Returns the UDim component for the horizontal axis, containing both .Scale and .Offset.

  • Height: UDimThe Y dimension scale and offset of the UDim2.

    A synonym for UDim2.Y. Returns the UDim component for the vertical axis, containing both .Scale and .Offset.

Methods 1

  • Lerp(goal: UDim2, alpha: number) → UDim2Returns a UDim2 interpolated linearly between the value and the given goal.

    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
  • UDim2 - UDim2 → UDim2

Reference text from the Roblox Creator Documentation, licensed CC BY 4.0, reorganized by rbxtoolshub.com · Studio 0.743.0.7431133.