Lesson 1 of 6
UI fundamentals: ScreenGui, UDim2, layouts
Learn Roblox UI from Beacon Yard's real HUD and shop, from ScreenGui and DisplayOrder to UDim2 scale and offset, list layouts, UIScale and phone safe areas.
By the end you can
- Explain where a ScreenGui lives, who can see it, and how DisplayOrder stacks the HUD under the shop
- Read and write UDim2 sizes and positions in scale and offset, and predict their pixel size on a given screen
- Lay out a panel with UIListLayout, UIPadding and UIScale, and keep it inside the safe area on a phone
Before this: Remotes: events, functions, unreliable, buffers, Input everywhere, part 1: keyboard, gamepad, touch and accessibility
Step 1 of 10
Open the shop and look closely
Walk up to the quartermaster in Beacon Yard and hold the prompt. A dark panel with a gold edge appears in the middle of the screen: a title, three coloured buttons and a Close button. The HUD in the corner is still there underneath it. Everything you see on that screen is one kind of thing: a GUI object inside a ScreenGuiScreenGuiA container that draws 2D interface objects over one player's view of the game.Think of it as a sheet of glass in front of one player's screen..

Select a numbered pin, or a row below, to read what it marks.
The shop over the HUD in a playtest. Select the pins to see which line of code made each part.
Both panels are built in code, in src/client/ShopGui.luau and src/client/Hud.luau. Neither one exists in the place file. A LocalScript creates them for one player when that player joins.
Two players are in the yard. Player A opens the shop. What does player B see?
Press 1 to 4 to choose, Enter to check.
Step 2 of 10
A screen that belongs to one player
A ScreenGui is a container that draws 2D objects on top of the 3D world. All of it is stored and changed on the client1. You can make one in two ways. Put it in StarterGui and Roblox copies it into each player's PlayerGui when they spawn. Or create it from a LocalScript and parent it to PlayerGui yourself, which is what Beacon Yard does.
The shop is drawn on one player's screen at home. The server never sees it. When a player presses Buy, the button is the controller: it can only send a request to the arena, and the server decides.
Think of it as Your screen and controller at home
Client sideRemember: The client is your screen and controller at home.
Two settings matter on every ScreenGui. ResetOnSpawn = false keeps it alive when the character respawns, since the LocalScript that built it does not run again. DisplayOrder stacks ScreenGuis: higher draws on top. The HUD uses 10 and the shop uses 20.
screen.ResetOnSpawn = false
screen.DisplayOrder = 20
screen.ZIndexBehavior = Enum.ZIndexBehavior.Sibling
screen.IgnoreGuiInset = false
The HUD's ScreenGui has DisplayOrder 10. What is the smallest whole-number DisplayOrder a new settings menu needs so it always draws above the shop?
Step 3 of 10
UDim2: a fraction plus some pixels
Every GUI object has a Size and a Position, and both are a UDim2UDim2A 2D size or position made of a scale (a fraction of the parent) and an offset (pixels) on each axis.Think of it as half the table, plus two fingers.. A UDim2 holds two numbers per axis: a scale, which is a fraction of the parent's size, and an offset, which is a number of pixels added on top2. UDim2.new(1, 0, 0, 84) means "full parent width, plus nothing; zero parent height, plus 84 pixels". That is exactly how every shop button is sized.
UDim2.fromScale(0.5, 0.5) and UDim2.fromOffset(400, 480) are shortcuts for "scale only" and "offset only". The shop panel uses both: its position is half the screen in each direction, its size is a fixed 400 by 480 pixels, and AnchorPoint = Vector2.new(0.5, 0.5) makes the position refer to the panel's centre instead of its top-left corner.
A label is sized UDim2.new(0.5, -20, 0, 40) inside a frame 300 pixels wide. How wide is it?
label.Size = UDim2.new(0.5, -20, 0, 40)
-- parent frame is 300 x 200 pixels
Press 1 to 4 to choose, Enter to check.
Step 4 of 10
Let a layout place the children
Placing every child by hand breaks the moment you add one. A UI layoutUI layoutAn invisible child such as UIListLayout or UIGridLayout that positions its sibling GUI objects for you.Think of it as a shelf with fixed gaps: you add items and they line up. object does it for you. Put a UIListLayout inside a frame and it stacks every sibling in a row or a column, in LayoutOrder order, with a fixed gap3. A UIPadding keeps the children away from the frame's edges. The shop uses both, which is why its buttons have no Position at all.
padding.PaddingTop = UDim.new(0, 18)
padding.PaddingBottom = UDim.new(0, 18)
padding.PaddingLeft = UDim.new(0, 18)
padding.PaddingRight = UDim.new(0, 18)
padding.Parent = panel
local layout = Instance.new("UIListLayout")
layout.FillDirection = Enum.FillDirection.Vertical
layout.HorizontalAlignment = Enum.HorizontalAlignment.Center
layout.SortOrder = Enum.SortOrder.LayoutOrder
layout.Padding = UDim.new(0, 12)
layout.Parent = panel
At m06 the order of the buttons comes from LayoutOrder: Title 1, Speed 2, Shield 3, Coin Pack 4, Close 5. Change Shield to 6 and it drops to the bottom. Other modifiers do similar jobs. UIGridLayout makes a grid of equal cells, UIFlexItem lets one child grow or shrink to fill the leftover space, and UIAspectRatioConstraint keeps a frame's shape when its size is in scale.
Match each instance to its job in the shop panel.
Step 5 of 10
The same panel on a phone
A panel that is 400 by 480 pixels fills a third of a laptop screen and most of a phone held sideways. Beacon Yard solves this with one shared module, UiScale, that adds a UIScale to each ScreenGui. A UIScale multiplies the size of everything under it, children and strokes included4.
local function apply(camera: Camera)
local size = camera.ViewportSize
if size.X <= 0 or size.Y <= 0 then
return
end
local shorter = math.min(size.X, size.Y)
uiScale.Scale = math.clamp(shorter / 720, 0.65, 1.4)
The module divides the shorter side of the screen by 720 and keeps the result between 0.65 and 1.4. Phones also have notches, rounded corners and the Roblox top bar. ScreenInsets on a ScreenGui decides whether your UI stays inside that safe area, and IgnoreGuiInset = false, which both panels use, keeps them below the top bar.
The UDim2 phone
Goal Resize the device until the shop panel touches the screen edge, then fix it with a UIScale clamp or a scale-based size.

A phone frame you can resize. Pick Scale, Offset or UIScale for the shop panel and watch where each one breaks.
A phone's screen is 844 by 390 pixels in landscape. What UIScale does UiScale.attach set? Round to two decimals.
Step 6 of 10
Where the screen picture breaks
Where does it break?“Your screen and controller at home” is a good picture of the client. Where does it stop being true?
It breaks here. The client also simulates your own character's movement and sends it up, so it is more than a screen.
The true model. Each player's device runs its own copy of the game for display and input. It owns its character's physics by default, which is why movement feels instant and why a cheater can move strangely.
A screen at home only shows things. But the client in Roblox runs code: it builds the GUI, reads clicks and can change any of it. An exploiter can make the Speed button say "free" or fire ShopBuy a hundred times a second. That is why the button only sends a request, and why ShopService on the server checks the price and the balance.
This is a beginner's version of the Speed button. Which line is the bug?
Press 1 to 5 to choose, Enter to check.
Step 7 of 10
How studios build UI
Beacon Yard builds its UI with Instance.new so every property is in a file you can read and diff. That is one of several common ways, and studios mix them.
Other ways pros do this
| Option | What it is | When pros pick it | Trade-offs |
|---|---|---|---|
| Studio's UI tools | Draw frames and buttons in the viewport, set properties in the Properties window, save them in StarterGui. | Static menus, fast iteration with a designer, learning what each property does. | The layout lives in the place file, so Git cannot diff it unless you export it as a model. |
| Instance.new in Luau | Build the tree in a LocalScript, as ShopGui and Hud do. | Small UIs in a code-first repo, UI generated from data. | Verbose, and every state change is a manual property write you must not forget. |
| A UI framework | React-lua, Fusion or Vide describe the UI as a function of state. | Large UIs with many screens, lists and state, and teams that share components. | A dependency to learn and update. The next lesson compares them. |
| UI styling | StyleSheets with rules, tokens and themes, edited in the Style Editor. | Shared colours and fonts across many screens, light and dark themes. | Newer engine feature; teams still settle on conventions. |
Which of these belong in client UI code in Beacon Yard?
Press 1 to 5 to choose, Enter to check.
Step 8 of 10
Build along: a coins pill that fits a phone
You will add a small, empty coins pill to the top-right corner (putting the coin count inside it is wiring for later; here you practise sizing), sized in scale so it grows with the screen, and check it in the device emulator. Work on your own branch of the game repo. The game's own next step, the m07-feel milestone, polishes the shop instead: it pops in with a tween, shows your coins and dims what you cannot afford. Compare with git diff m06-drone-wrench m07-feel -- src/client/ShopGui.luau when you are done.
Build along
src/client/Hud.luau
Check out
m06-drone-wrench, runrojo serve, open the place and connect the Rojo plugin.You should see Studio opens the place and the Rojo plugin says Connected.
In
Hud.start, after the panel, create aFramenamedCoinsPillwithAnchorPoint = Vector2.new(1, 0),Position = UDim2.new(1, -16, 0, 16)andSize = UDim2.fromScale(0.2, 0.08). Add aUIStroketo it withColor = Color3.fromRGB(255, 200, 40)andThickness = 2for the yellow edge. Parent the frame toscreen. Press Play.You should see A yellow-edged empty frame appears in the top-right corner during Play, about a fifth of the screen wide.
Add a
UIAspectRatioConstraintwithAspectRatio = 3to the pill. In the Test tab, open the device emulator and switch between a laptop and a phone in landscape.You should see The pill keeps the same shape when you switch devices in the emulator. At 1280 by 720 it narrows to about 173 pixels wide, roughly 13% of the screen, because the aspect ratio caps the width at three times the height.
Check that the HUD ScreenGui has
IgnoreGuiInset = falseandScreenInsets = Enum.ScreenInsets.CoreUISafeInsets(the default whenIgnoreGuiInsetis false), and check the phone again.You should see The pill sits fully inside the screen on the phone, clear of the notch and the top bar.
Step 9 of 10
Challenges
Level 1, Apprentice
Challenge
Change the shop panel from UDim2.fromOffset(400, 480) to a size in scale that matches on a laptop and still fits on a phone.
- Start from
- The game at milestone m06 (download)
Done means
- The shop panel is sized in scale, not offset
- On a 1280 by 720 window the panel is still about 400 by 480 pixels
- On a phone in the emulator the panel fits on screen
Meet the criteria above, then record your own result. No test grades this check.
Why does the client-only settings challenge run on the client instead of the server?
Press 1 to 4 to choose, Enter to check.
Step 10 of 10
Recap
Recap
- A ScreenGui lives in one player's PlayerGui; DisplayOrder stacks the HUD (10) under the shop (20).
- UDim2 is scale times the parent plus an offset in pixels; AnchorPoint picks which point of the object the position refers to.
- Layouts, padding and one UIScale clamped between 0.65 and 1.4 keep the same panel usable from a phone to a monitor.
The client is your screen and controller at home, until the client also simulates your own character's movement and sends it up, so it is more than a screen.
Queued for review