Module 11 · Roblox UI systems
Layouts and constraints
Let layout objects arrange repeated UI and constraints preserve useful shape.
What you will learn
- Choose list or grid layout
- Use padding, aspect constraints, and AutomaticSize
- Avoid repeated manual positioning
- layout
- A UI object that arranges sibling GuiObjects.
- constraint
- A UI object that limits size or shape according to a rule.
Loading saved progress…
Understand
Read the idea and follow a worked example.
Why this matters
A Coin Quest inventory or shop contains repeated entries that should reflow consistently as content and screen size change.
The mental model
UIListLayout arranges one sequence; UIGridLayout arranges cells in rows and columns. UIPadding adds container space.
UIAspectRatioConstraint preserves a shape. AutomaticSize lets content drive a supported dimension, but needs bounded layout rules.
New words and symbols
--!strict asks Studio to check your code for type mistakes. It is an instruction for the editor and produces no Output message.
Matching quotes such as "hello" surround a string: a piece of text. The quotation marks tell Luau where the text starts and ends.
local is read as “local”: it creates a name that is available only in the current code scope.
= is read as “is assigned”: it evaluates the right side and stores that value in the name on the left.
. is read as “dot”: it accesses a named property or table field.
A tiny example
--!strictlocal list = Instance.new("Frame")list.Name = "ShopList"list.Size = UDim2.fromScale(1, 0)list.AutomaticSize = Enum.AutomaticSize.Ylocal padding = Instance.new("UIPadding")padding.PaddingTop = UDim.new(0, 12)padding.PaddingBottom = UDim.new(0, 12)padding.Parent = listlocal layout = Instance.new("UIListLayout")layout.Padding = UDim.new(0, 8)layout.Parent = listlist.Parent = script.ParentLine by line
- 3
The Frame will contain repeated shop entries.
- 5
Width follows its parent while starting height is content-driven.
- 6
AutomaticSize grows the Y dimension.
- 8
UIPadding owns edge spacing.
- 13
UIListLayout arranges sibling entries in a sequence.
- 14
Layout spacing is separate from container edges.
- 16
The complete container is parented last.
Read the code aloud
Read one statement at a time: name the value being read, what the operation does, and where its result goes. Keep identifiers exactly as written so you can find them again in the code.
Pause at calls, conditions, and loops. Explain when the body runs before moving to the next statement; use the line notes above when a symbol is unfamiliar.
Execution trace
Begin at the first executable statement. Comments and blank lines do not run; a branch chooses which block runs, and a loop may revisit its body.
Line 3: The Frame will contain repeated shop entries.
Line 5: Width follows its parent while starting height is content-driven.
Line 6: AutomaticSize grows the Y dimension.
Line 8: UIPadding owns edge spacing.
Line 13: UIListLayout arranges sibling entries in a sequence.
Line 14: Layout spacing is separate from container edges.
Line 16: The complete container is parented last.
State before and after
Before running, identify the starting values and any existing Studio objects this example needs. List what you expect to change.
After your practice change, check this result: Entries arrange without individual Position assignments and remain inside padded bounds.
Reading or printing a value leaves it unchanged. Look for assignments, calls that change state, and property updates to explain each change you observe.
Predict before running
Which object spaces repeated vertical entries?
Try it
Mark each step after you have tried it.
Common mistake
Assigning a separate Y position to every item duplicates layout logic and breaks when an item is inserted. Let a layout object own repeated positioning.
Checkpoint
Submit once you have considered every question. Retries are unlimited.
Recap
- Layouts arrange sibling UI.
- Padding and constraints encode reusable rules.
- AutomaticSize can follow content within clear bounds.
Next: Next, you will activate buttons on any device and provide restrained feedback.
Studio Companion
Not connected
Connect once. Compatible challenges will prepare automatically as you reach them.