UDim2
UI positions and sizes that hold their layout when the viewport resizes
Constructors
1 member Access: shared
- new
(scaleX: number?, offsetX: number?, scaleY: number?, offsetY: number?) -> UDim2 make a 2d dimension of scale and offset
Parameters
Name Type Description scaleX number? Fraction of the parent width. offsetX number? Pixels added on the X axis. scaleY number? Fraction of the parent height. offsetY number? Pixels added on the Y axis. returns UDim2 —
Positioning UI Elements with Scale and Offset
Lifecycle: Client
Each axis holds a fraction of the parent plus a pixel offset, so a layout survives a resize.
Luau
-- Centered horizontally and vertically with a 24px bottom offsetlocal centerBadge = UDim2.new(0.5, 0, 0.5, 24)-- Responsive size: 90% screen width minus 32px margins, fixed 64px heightlocal actionPanel = UDim2.new(0.9, -32, 0, 64)-- Offset arithmeticlocal shifted = centerBadge + UDim2.fromOffset(0, 12)