UDim2

A UDim2, which is basically two UDims (Universal Dimensions) being represented within the same object, is a Lua object which stores information about the size and position of GUI elements. The difference between a UDim and UDim2 is that a UDim2 represents a two dimensional plane with x and y coordinates while a UDim only accounts for one coordinate.

The constructor takes parameters in the order: xscale, xoffset, yscale, yoffset.

Members
X.Scale and Y.Scale set the size or position of an element proportionally to the size of its parent. A value of 1 will set the child to the same size or position as its parent on the specified axis, and 0 will make it have a size 0% of its parent, and have a position 0% of its parent on the specified axis.

X.Offset and Y.Offset set the size or position of an element in pixels. This number is added to the Scale parameters, after their size has been calculated: these values are offsets.

The size of a GUI is calculated using the formula: Size = Scale*Parent.AbsoluteSize + Offset

The position of a GUI is calculated using the formula: Position = Parent.AbsolutePosition + Scale*Parent.AbsoluteSize + Offset

Example
local frame = Instance.new("Frame") frame.Position = UDim2.new(0.5, -50, 1, -100) frame.Size = UDim2.new(0, 100, 0, 100) frame.Parent = GUI

This creates a 100×100 pixel rectangle, centered at the bottom of the screen.