Lesson 2
Scale, Offset and anchor points
Goal: Size and center UI for any screen.
about 6 min3 practice exercises
Every UI object has a Position and a Size, and both are a UDim2. Each axis has two numbers:
- Scale is a share of the parent:
0.5is half its width or height. - Offset is a fixed number of pixels.
The two are added together.
Scale 0.5: half the parent, on any screen
Offset 120: always 120 pixels
A button sized in Offset is the same number of pixels on a phone and on a 4K monitor, so it is huge on one or tiny on the other. Size the main pieces of your UI with Scale, and use Offset for small fixed things such as padding.
local window = script.Parent
window.Size = UDim2.fromScale(0.6, 0.7)
window.AnchorPoint = Vector2.new(0.5, 0.5)
window.Position = UDim2.fromScale(0.5, 0.5)
AnchorPoint is the point on the object that Position refers to. The default (0, 0) is the top-left corner. Set it to (0.5, 0.5) and position 0.5, 0.5 puts the object's center in the center of its parent, which is how you center anything.
Go deeper on Rodex
Sources
Checked against Roblox's documentation on . The lesson is in our own words; these pages are the source of truth.