Hand-written by Joseph San Nicolas, Roblox Developer
UDim2
Constructors
| Name | Description |
| new() | Returns a UDim2 with both dimensions set to zero. Equivalent to UDim2.new(0, 0, 0, 0). |
| new(xScale: number,xOffset: number,yScale: number,yOffset: number) | Returns a UDim2 from four numbers defining both axes: xScale and xOffset for the X dimension, yScale and yOffset for the Y dimension. Scale is a relative fraction of the parent container's size; offset is an absolute number of logical pixels added after scaling. All parameters default to 0. |
| new(x: UDim,y: UDim) | Constructs a UDim2 by composing two UDim values directly - x becomes the horizontal (X) dimension and y becomes the vertical (Y) dimension. |
| fromScale(xScale: number,yScale: number) | Returns a UDim2 with the given scale components and no offsets. Equivalent to UDim2.new(xScale, 0, yScale, 0). |
| fromOffset(xOffset: number,yOffset: number) | Returns a UDim2 with the given offset components and no scaling. Equivalent to UDim2.new(0, xOffset, 0, yOffset). |
Code Snippet
local Frame = Instance.new("Frame")
Frame.Parent = script.Parent
Frame.Size = UDim2.new(0.5, 20, 0, 100) -- 50% of parent width + 20px, fixed 100px tall
Frame.Position = UDim2.fromScale(0.25, 0.25)
local goalSize = UDim2.fromOffset(300, 150)
Frame.Size = Frame.Size:Lerp(goalSize, 0.5)
Properties
| Name | Type | Description |
| X | UDim | The UDim component for the horizontal axis, containing both a relative Scale and an absolute Offset. Equivalent to Width. |
| Y | UDim | The UDim component for the vertical axis, containing both a relative Scale and an absolute Offset. Equivalent to Height. |
| Width | UDim | A synonym for X; returns the UDim component for the horizontal axis. |
| Height | UDim | A synonym for Y; returns the UDim component for the vertical axis. |
Methods
| Name | Parameters | Returns | Description |
| Lerp(goal: UDim2,alpha: number):UDim2 | goal: UDim2, alpha: number | UDim2 | Returns a UDim2 interpolated linearly between this UDim2 and the given goal, with each axis's scale and offset interpolated independently. The alpha value should be within the range of 0 to 1. |