Lesson 2 of 6

UI design: Figma to Studio, hierarchy, accessibility

Design Roblox game UI in Figma from zero, map frames and auto layout to UDim2 and UIListLayout, and check hierarchy, contrast and accessibility on Beacon Yard's shop.

Tool lesson, about 70 minutes, 13 steps

By the end you can

  • Mock up a game screen in Figma with frames, auto layout and a button component, and export an asset for Roblox
  • Turn a Figma frame's pixel numbers into UDim2 scale and offset, and auto layout into UIListLayout and UIPadding
  • Check a design for hierarchy, contrast, text size and colour-blind safety, and name the Roblox settings that help
  • Move hard-coded UI colours into StyleSheet tokens and rules linked to a ScreenGui

Before this: UI fundamentals: ScreenGui, UDim2, layouts

1One button that almost fails

Look at the Coin Pack button in Beacon Yard's shop. White text on a gold background, Color3.fromRGB(168, 112, 28). It looks fine on a laptop. Measure it and the white-on-gold pair has a Contrast ratioContrast ratioA number from 1 to 21 that compares how bright two colours are; text needs 4.5 to 1, or 3 to 1 when large.Think of it as how far apart the text and its background look to a tired eye. of about 4.2 to 1. The common accessibility guideline asks for 4.5 to 1 for normal text and 3 to 1 for large text1.

Roblox Studio
The Beacon Yard shop panel with Speed in green, Shield in blue, Coin Pack in gold and a grey Close button, all with white text.

Select a numbered pin, or a row below, to read what it marks.

Figure 1.1.

The same shop as the last lesson, measured. Each pin gives the text contrast of one button.

The buttons use TextSize = 26 with an ExtraBold font, which counts as large text, so the gold button passes. But UiScale can shrink the whole shop to 0.65 on a phone. Then the text is about 17 pixels tall, no longer "large", and the same colours fail. Design decisions and code decisions meet right here.

On a small phone, UiScale sets 0.65 and the Coin Pack text drops to about 17 pixels. What is the cleanest fix?

  1. Darken the gold background until white text reaches 4.5 to 1
  2. Turn off UIScale for the shop
  3. Make the text yellow
  4. Add a drop shadow and keep the colours
Answer

Darken the gold background until white text reaches 4.5 to 1. A darker gold raises the contrast above 4.5 to 1, so the button passes at any size. Turning off UIScale breaks the layout on phones, and a shadow does not change the measured contrast of the letters.

Open this step in lesson mode · Link to this step · This confused me

2Why design before you build

Building UI in Luau is slow to change. Every colour, gap and font is a property write in a file, and you only see the result after Play. A design tool lets you try ten layouts in the time one takes in code, show them to someone, and only then build the winner. Most studios have a UI designer who works this way and hands the result to a UI scripter.

FigmaFigmaA browser and desktop design tool for screens: frames, auto layout, components and variables.Think of it as a whiteboard where every shape knows how to resize. is the tool most of them use. It runs in a browser or a desktop app, and its free Starter plan includes unlimited drafts, which is enough for this course2. You will need a Figma account; the BuildAlong at the end of this lesson walks through it.

Which of these are faster to try in a design tool than in Studio?

  1. Three different orders for the shop buttons
  2. A darker gold for the Coin Pack
  3. Whether ShopBuy is rejected when coins are short
  4. How the panel looks on a phone and on a monitor
  5. How long the purchase takes to save
Answer

Three different orders for the shop buttons; A darker gold for the Coin Pack; How the panel looks on a phone and on a monitor. Layout, colour and screen sizes are pure design questions. Whether the server rejects a purchase, and how long a save takes, only exist in the running game.

Open this step in lesson mode · Link to this step · This confused me

3Frames and auto layout

In Figma everything sits on a canvas. A frame is a box with a fixed size that holds other layers, like a screen. Make one frame per target screen: 1280 by 720 for a laptop and 844 by 390 for a phone held sideways3.

Auto layout turns a frame into a stack. You choose a direction, the gap between items, the padding at the edges and the alignment, and Figma arranges the children for you. Each child is set to hug contents (its size follows what is inside), fill container (it takes the remaining space) or fixed4. If that sounds familiar, it should: it is the same idea as the shop's UIListLayout and UIPadding.

Go deeper Hug, fill and fixed in Roblox terms

Figma's hug contents is AutomaticSize on a Roblox GUI object: the object grows to fit its children. Fill container is a scale of 1 on that axis, or a UIFlexItem when several children share the leftover space in a UIListLayout. Fixed is an offset-only size. Choosing one per axis in the design tells the scripter exactly which Size to write.

Match each Figma idea to the Roblox piece that does the same job.

  1. Vertical auto layout with a 12 px gap
  2. Auto layout padding of 18 px
  3. A child set to fill container width
  4. Corner radius 10
Answer

Vertical auto layout with a 12 px gap: UIListLayout, FillDirection Vertical, Padding 12; Auto layout padding of 18 px: UIPadding with 18 on every side; A child set to fill container width: Size with X scale 1 (or a UIFlexItem); Corner radius 10: UICorner with CornerRadius 10. Auto layout maps almost one to one onto UIListLayout and UIPadding. Fill container is a scale of 1 on that axis, or a UIFlexItem when the leftover space must be shared.

Open this step in lesson mode · Link to this step · This confused me

4Components: design a button once

Draw one shop button: a rectangle with rounded corners and a text layer, inside an auto layout frame. Select it and choose Create component. That is now the main component. Every copy you drag out is an instance that follows the main one, so changing the gold once changes every button5. Variants put several states of a component side by side: Default, Pressed, Disabled.

Name colours too. Figma's variables and styles let you call the gold price/pack instead of #A8701C. Roblox has the same idea now: Design tokenDesign tokenA named value, such as a colour or a size, that many UI pieces share.Think of it as a paint colour with a label on the tin instead of a swatch on the wall.s in a StyleSheet, edited in the Style Editor, so one token changes every button that uses it6.

A button design has a job beyond looking good: it tells the player what happened to their request. Pressing Speed writes a note to the front desk. The server might say yes, or "Not enough coins", or "Already owned". Design a state for each answer, not only for the press.

Think of it as A note to the front-desk clerk

Both sidesRemember: A RemoteEvent is a note to the front-desk clerk.

ShopService can send these Feedback messages for Speed. Which button states does your design need?

  1. Default, with the price
  2. Bought, after "Speed"
  3. Rejected, after "Not enough coins"
  4. Owned, after "Already owned"
  5. A state that shows the coins were taken before the server replies
Answer

Default, with the price; Bought, after "Speed"; Rejected, after "Not enough coins"; Owned, after "Already owned". buySpeed answers with buy, Not enough coins or Already owned. The client must never show coins taken before the server's answer, because the server may say no.

Open this step in lesson mode · Link to this step · This confused me

5From pixels in a frame to UDim2

Figma gives you pixels. Roblox wants a scale, an offset or both. The rule: divide the child's size by the frame's size to get a scale, and keep pixels as offset for things that must stay a fixed size, such as a border or a small gap.

Luau
-- Figma frame: 1280 x 720. Shop panel: 400 x 480, centred.
local function scale(childPx, framePx)
	return math.round(childPx / framePx * 1000) / 1000
end
 
print("width scale " .. scale(400, 1280))
print("height scale " .. scale(480, 720))
-- A panel in scale keeps its share of the screen,
-- so add a UIAspectRatioConstraint to keep its shape.
print("aspect " .. scale(400, 480))
Figure 5.1. Expected output: width scale 0.313 height scale 0.667 aspect 0.833

Exported art follows the same path. Select a layer, add an export setting such as PNG at 2x, and export7. Upload the PNG as an Image in Studio's Asset Manager and use it on an ImageLabel. For a button background that must stretch without blurring its corners, use 9-slice: ScaleType = Slice with a SliceCenter rectangle8.

The shop panel is 400 by 480 pixels. What AspectRatio (width divided by height) should its UIAspectRatioConstraint use? Two decimals.

Answer

0.83 (within 0.005). 400 / 480 is about 0.833. With that constraint, a panel sized in scale keeps the shop's shape on every screen.

Open this step in lesson mode · Link to this step · This confused me

6Visual hierarchy: what the eye reads first

Hierarchy is the order in which a player's eye reads the screen. Size, colour, contrast and position set it. In the shop the title is largest, the three buy buttons are bright and equal, and Close is grey and last. That says: these three are your choices, and leaving is quiet. Roblox's own design guide gives the same advice: make the important action obvious and keep the rest calm9.

Hierarchy also means the HUD must stay readable while the shop is open, and a player on a phone must reach every button with a thumb. Check your frames at phone size before you call a design done.

Why is the Close button dark grey while the buy buttons are bright?

  1. Low emphasis: closing is always available but should not compete with the choices
  2. Grey is the only colour Roblox allows for close buttons
  3. Grey has the lowest contrast, so it is easier to read
  4. So colour-blind players cannot press it by mistake
Answer

Low emphasis: closing is always available but should not compete with the choices. Colour sets emphasis. The grey Close still has high text contrast (about 11.6 to 1), so it is easy to read, but it does not shout.

Open this step in lesson mode · Link to this step · This confused me

7Accessibility: contrast, size, colour and motion

Over 5 percent of people have some form of colour blindness10. In grayscale, Speed, Shield and Coin Pack differ only in their words, which is fine, because each button is labelled. A design that says "press the green one" is not.

Roblox gives players settings your UI should respect. GuiService.PreferredTextSize is the player's text size choice, and it grows text on its own unless you turn on TextScaled. GuiService.ReducedMotionEnabled means the player wants fewer UI animations. GuiService.PreferredTransparency asks for more opaque backgrounds10. Beacon Yard's m07-feel milestone adds its own two settings, ReducedMotion and LargeText, as player attributes that only the server writes. ReducedMotion starts from the player's Roblox Reduce Motion toggle, skips the shop's pop-in tween and thins the particle bursts; LargeText multiplies registered labels by 1.3 on top of Roblox's own text size setting.

Luau
-- WCAG contrast ratio between two colours (0 to 255 each).
local function channel(c)
	c = c / 255
	if c <= 0.04045 then return c / 12.92 end
	return ((c + 0.055) / 1.055) ^ 2.4
end
local function luminance(r, g, b)
	return 0.2126 * channel(r) + 0.7152 * channel(g) + 0.0722 * channel(b)
end
local function ratio(a, b)
	local la, lb = luminance(table.unpack(a)), luminance(table.unpack(b))
	local hi, lo = math.max(la, lb), math.min(la, lb)
	return math.round((hi + 0.05) / (lo + 0.05) * 100) / 100
end
 
local white = { 255, 255, 255 }
print("speed " .. ratio(white, { 28, 122, 78 }))
print("pack " .. ratio(white, { 168, 112, 28 }))
Figure 7.1. Expected output: speed 5.33 pack 4.2

A label has TextScaled turned on. A player sets their Roblox text size to large. What happens to that label?

  1. Nothing; TextScaled labels are not scaled by PreferredTextSize
  2. Its text grows like every other label
  3. It turns into a TextBox
  4. Roblox shows an accessibility warning
Answer

Nothing; TextScaled labels are not scaled by PreferredTextSize. The accessibility page says TextScaled text is not changed by PreferredTextSize. If you rely on TextScaled everywhere, the player's setting does nothing.

Open this step in lesson mode · Link to this step · This confused me

8Where the front desk breaks

Where does it break?“A note to the front-desk clerk” is a good picture of a remoteevent. Where does it stop being true?

It breaks here. The engine stamps the sender for you, but every other word on the note can be a lie.

The true model. A RemoteEvent carries a one-way message between a client and the server. The server always learns which player sent it; every other argument is untrusted input that the server must check.

A design can promise anything. A Figma prototype can show Speed as bought the instant you click. The game cannot, because the request may be refused or never arrive. Your mockup's "bought" state is a reply from the server, not the result of the click.

Your prototype greys out Speed and shows 0 coins the moment it is clicked. What should the real game do instead?

  1. Keep the price showing and wait for Feedback before changing the button
  2. Do exactly what the prototype does; it feels faster
  3. Take the coins on the client and refund them if the server says no
  4. Disable the button for every player in the server
Answer

Keep the price showing and wait for Feedback before changing the button. The client only knows what it asked for. It waits for the server's Feedback (buy, or a deny message) before showing a result. A short pressed state is fine; a fake purchase is not.

Open this step in lesson mode · Link to this step · This confused me

9Other tools, and when pros use them

Other ways pros do this

OptionWhat it isWhen pros pick itTrade-offs
FigmaBrowser and desktop design tool with frames, auto layout, components, variables and Dev Mode.The default in most studios and most UI job posts; easy to share a link with a scripter.Proprietary and online; advanced features and team libraries are paid.
PenpotOpen-source design tool with flex and grid layouts, components and self-hosting.You want an open format, no vendor account, or to host it yourself.Fewer plugins and fewer studios use it, so sharing files with clients is harder.
PhotopeaFree browser image editor that opens PSD files.Painting and cutting individual UI images: icons, frames, 9-slice backgrounds.An image editor, not a layout tool; no auto layout or components.
Designing in StudioBuild the UI directly with Studio's UI tools and the Style Editor.Small games, solo developers, or tuning a design that already exists.Slow to try alternatives, and the result lives in the place file unless you export it.

Put a typical UI workflow in order.

  1. Sketch the screen in Figma frames at phone and desktop size
  2. Export assets and write down tokens and sizes
  3. Turn repeated parts into components with their states
  4. Check contrast, text size and colour-blind safety
  5. Build it in Studio and test on a real phone
Answer

1. Sketch the screen in Figma frames at phone and desktop size 2. Turn repeated parts into components with their states 3. Check contrast, text size and colour-blind safety 4. Export assets and write down tokens and sizes 5. Build it in Studio and test on a real phone. Design, systematise, check, hand off, build. Fixing contrast in Figma costs seconds; fixing it after the build costs a code change and a retest.

Open this step in lesson mode · Link to this step · This confused me

10Build along: the shop in Figma

Build along

m06-drone-wrench

  1. Create a free Figma account at figma.com, then choose New design file from the home screen.

    You should see An empty Figma design file opens with a blank canvas.

  2. Press F for the frame tool, type 1280 and 720 in the size fields in the right panel, and name it Laptop. Make a second frame 844 by 390 named Phone.

    You should see Two frames, Laptop 1280×720 and Phone 844×390, sit side by side on the canvas.

  3. Draw a 400 by 480 frame (F) in the Laptop frame, fill it with #0E1218, and add auto layout (Shift + A) with vertical direction, gap 12 and padding 18. Auto layout belongs to frames, because a plain rectangle cannot hold children. Add a text layer "Quartermaster" and three button frames set to fill container width and 84 tall.

    You should see A dark panel 400×480 in the middle of the Laptop frame holds a title and three equal buttons spaced 12 apart.

  4. Turn one button into a component (Ctrl + Alt + K on Windows, Cmd + Option + K on Mac), delete the other two and drag in two instances. Override each instance's fill and label.

    You should see Changing the main component's colour changes all three buttons at once.

  5. Darken the Coin Pack fill until white text reaches 4.5 to 1, then copy the panel into the Phone frame and scale it to fit the 390 pixel height.

    You should see The Coin Pack instance reaches at least 4.5 to 1, checked with a contrast plugin or the Run cell above.

Open this step in lesson mode · Link to this step · This confused me

11Tokens in Studio: a StyleSheet for the settings panel

Your Figma file now names its colours. The game does not yet. At m14-ship, SettingsGui starts with four colour constants (GOLD, INK, ON, OFF) and sets every colour and corner radius by hand. A StyleSheet moves those values into named tokens that every menu can share6.

  • A token is an attribute on a StyleSheet, such as Gold. A rule uses it as the string "$Gold".
  • A StyleRule has a Selector and the properties it sets. "TextButton" matches a class, ".SettingOn" a tag, "#Panel" a name, and "#Panel > UIStroke" a direct child11.
  • A StyleLink inside a ScreenGui applies one sheet to everything in it. A StyleDerive lets a design sheet borrow the tokens of another.

The Style Editor on Studio's UI tab builds the same instances without code12. Here they come from code, so they live in Git:

luau
-- src/client/YardStyle.luau
local ReplicatedStorage = game:GetService("ReplicatedStorage")
 
local YardStyle = {}
 
local function rule(sheet: StyleSheet, selector: string, properties: { [string]: string })
	local made = Instance.new("StyleRule")
	made.Selector = selector
	made:SetProperties(properties)
	made.Parent = sheet
end
 
function YardStyle.link(screen: ScreenGui)
	local tokens = Instance.new("StyleSheet")
	tokens.Name = "YardTokens"
	tokens:SetAttribute("Ink", Color3.fromRGB(245, 247, 250))
	tokens:SetAttribute("Gold", Color3.fromRGB(232, 184, 74))
	tokens:SetAttribute("Night", Color3.fromRGB(14, 18, 24))
	tokens:SetAttribute("On", Color3.fromRGB(28, 122, 78))
	tokens:SetAttribute("Off", Color3.fromRGB(48, 52, 60))
	tokens:SetAttribute("Radius", UDim.new(0, 8))
	tokens:SetAttribute("PanelRadius", UDim.new(0, 10))
	tokens.Parent = ReplicatedStorage
 
	local design = Instance.new("StyleSheet")
	design.Name = "YardDesign"
	local derive = Instance.new("StyleDerive")
	derive.StyleSheet = tokens
	derive.Parent = design
	design.Parent = ReplicatedStorage
 
	rule(design, "#Panel", { BackgroundColor3 = "$Night" })
	rule(design, "#Panel > UIStroke", { Color = "$Gold" })
	rule(design, "TextButton > UICorner", { CornerRadius = "$Radius" })
	rule(design, "#Panel > UICorner", { CornerRadius = "$PanelRadius" })
	rule(design, "TextLabel, TextButton", { TextColor3 = "$Ink" })
	rule(design, ".SettingOn", { BackgroundColor3 = "$On" })
	rule(design, ".SettingOff", { BackgroundColor3 = "$Off" })
 
	local link = Instance.new("StyleLink")
	link.StyleSheet = design
	link.Parent = screen
end
 
return YardStyle

Build along

m14-ship

  • src/client/YardStyle.luau
  • src/client/SettingsGui.luau
  1. Add YardStyle.luau and call YardStyle.link(screen) in SettingsGui.start right after the ScreenGui is made. Delete the lines that set panel.BackgroundColor3, stroke.Color, title.TextColor3, button.TextColor3 and uiCorner.CornerRadius.

    You should see Opening Settings with P shows the same dark panel, gold outline and white text as before, and the Properties window flags those properties with a warning sign; hovering one names the style.

  2. In render, replace the BackgroundColor3 line with tags: add SettingOn and remove SettingOff when the setting is on, and the reverse when it is off.

    You should see Toggling a setting turns its button green and back to grey, with no colour set in SettingsGui.

  3. Change the Gold value in YardStyle.luau to another colour, let Rojo sync, and press Play again.

    You should see After one edit to the Gold token, the settings panel outline shows the new colour, and nothing else in SettingsGui changed.

You link YardDesign but forget to delete one line in SettingsGui. Then you change the Ink token to black. What colour is that button's text?

button.TextColor3 = INK -- still in toggle()
  1. Still white: a value set on the instance overrides the styled value
  2. Black: style rules always win
  3. Black on the first frame, then white
  4. An error, because a property cannot be both set and styled
Answer

Still white: a value set on the instance overrides the styled value. An explicit set is an override. That is why moving to tokens means deleting the hard-coded lines, not just adding a sheet. Reset to Default in the Properties window removes an override by hand.

Open this step in lesson mode · Link to this step · This confused me

12Challenges

Level 1, Apprentice

Challenge

Turn the shop's colours into named design tokens in Figma, and build a matching light-theme test of the shop panel.

Start from
The game at milestone m06 (download)

Done means

  • Local Figma color variables (or color styles) named by role for each shop colour (such as surface/panel, price/speed, price/shield, price/pack)
  • Every button instance uses a named variable, not a raw hex value
  • A second light-theme copy of the shop frame uses a matching light colour set (or a second variable mode if you are on Figma's Education or paid plan)

Hints

  1. Open the local variables panel with nothing selected.
  2. Name by job (price/speed), not by colour (green).
  3. Figma's free Starter plan allows local variables in one default mode; adding extra variable modes requires an Education or Professional+ plan. On Starter, use a second colour group or colour styles to test a light theme.

Level 3, Professional

Challenge

Write the three functions in challenges/work/ui_design.luau in the game repo (start from the m14-ship tag to get challenges/work/ui_design.luau and challenges/ui-design.luau). The test checks them against the shop's real colours, including the Coin Pack at UIScale 0.65. The written solution is challenges/solutions/ui-design.md.

Start from
The game at milestone m14 (download)
Grade it
In Studio, press Play, then run game.ServerScriptService.RunGameTests:Invoke("ui-design", "ui-design-contrast") in the server command bar. Copy the pass code from Output.

Done means

  • challenges/work/ui_design.luau exports contrastRatio(a, b), toScale(px, framePx) and passes(ratio, textPx, bold)
  • contrastRatio computes the WCAG contrast ratio of two RGB colours
  • toScale converts a Figma pixel size to a UDim2 scale rounded to 3 decimal places (math.round(px / framePx * 1000) / 1000)
  • passes returns whether a contrast ratio meets WCAG AA for the given text pixel size and bold flag
  • challenges/ui-design.luau prints TEST PASS for every check

Hints

  1. Linearise each channel first: values at or below 0.04045 divide by 12.92.
  2. toScale must round to 3 decimals: 400 / 1280 -> 0.313, 480 / 720 -> 0.667.
  3. Large text is at least 24 pixels, or at least 18.66 pixels and bold.
  4. Large text needs 3 to 1; everything else needs 4.5 to 1.

A bold label is 26 pixels tall at UIScale 1. Below what UIScale does it stop counting as large bold text (18.66 pixels)? Two decimals.

Answer

0.72 (within 0.01). 18.66 / 26 is about 0.72. Beacon Yard's UiScale can go down to 0.65, so on small phones the shop's text is normal-size text and needs 4.5 to 1.

Open this step in lesson mode · Link to this step · This confused me

13Recap

Recap

  1. Design in Figma first: frames per screen size, auto layout for stacks, components with every state the server can answer with.
  2. Auto layout maps to UIListLayout and UIPadding; pixel sizes become a scale by dividing by the frame, plus an aspect ratio constraint.
  3. Check contrast at the smallest UIScale your game uses: the gold Coin Pack passes as large text at 26 pixels and fails at 0.65.
  4. In Studio, tokens are StyleSheet attributes used as $Name in StyleRules, a StyleLink applies the sheet to a ScreenGui, and a value set on the instance overrides the style.

A RemoteEvent is a note to the front-desk clerk, until the engine stamps the sender for you, but every other word on the note can be a lie.

Next Console, VR and the 10-foot screen

Open this step in lesson mode · Link to this step · This confused me