Blog / Figma Pipeline 5 min read

Figma to Roblox UI with AI: 9-slice insets, editable TextLabels, and repeat grids

How penui preserves Figma 9-slice SliceCenter insets, Fredoka One and Montserrat text layers, imageOrigin glow padding, and repeatPositions for AI-built Roblox ScreenGuis.

Exporting a Figma frame as a flat PNG and dropping it into an ImageLabel looks fine for five minutes—until you resize a shop panel for a wider description, localize a button label to Spanish, or clone six daily-reward tiles across a grid. Everything breaks at once: corners stretch into ovals, outer glows get clipped into hard black boxes, and text cannot be changed without reopening Figma.

When an AI agent builds Roblox UI from penui, it does not consume flat screenshots. Every component and pre-split unit in the library carries machine-readable geometry extracted from the source .fig file so the generated Luau reproduces designer intent cleanly.

1. Pre-split layers: full.png, notext.png, and parts/*.png

Every penui unit ships with separate visual variants and part metadata:

If a designer baked a stud pattern or diagonal sheen as its own layer, your agent can inspect the layers via get_unit { id, parts_images: true } and pass layers: { omit: ["<part-id>"], bounds: "selection" } to drop or soften that layer cleanly without regenerating artwork.

2. Why imageOrigin keeps glows and shadows intact

In Figma, drop shadows and outer neon glows bleed outside a frame's logical bounds. A 400x90 button with a soft shadow and outer glow might actually occupy 419x118 pixels on canvas. If an exporter trims to the logical box, the glow gets sliced off with a hard edge; if it expands the logical box, spacing between sibling buttons drifts.

penui separates the two boxes in metadata:

In Luau, the root container keeps UDim2.fromOffset(size.w, size.h) while the child ImageLabel is placed at UDim2.fromOffset(imageOrigin.x, imageOrigin.y) with UDim2.fromOffset(imageSize.w, imageSize.h). Layout math stays exact while glows bleed naturally outside the frame.

3. Automatic 9-slice (SliceCenter) for resizable panels

Rounded borders, metal rims, and ornate corners cannot be stretched uniformly along one axis without distorting the corner radius. When a component has nineSlice.insetPx and clean bounds (imageOrigin at 0,0 and imageSize.w === size.w), penui compiles Roblox 9-slice properties directly:

-- 9-slice: resize root freely, art stretches without distorting corners
img.ScaleType = Enum.ScaleType.Slice
img.SliceCenter = Rect.new(i * ps, i * ps, (w - i) * ps, (h - i) * ps)
-- When using @2x artwork (ps = 2), SliceScale compensates so corner px stay 1:1
img.SliceScale = 0.5
img.Size = UDim2.fromScale(1, 1)

Notice the ps multiplier (imageScale): Roblox defines SliceCenter in texture pixels, not design pixels. Scaling by ps and setting SliceScale = 1 / ps ensures @2x crisp panels slice at the exact corner pixel without manual math.

4. Editable TextLabels with Fredoka One and Montserrat

Each entry in a component's texts[] array records content, bounding box (x, y, w, h), font, fontStyle, size, color, align, stroke, and shadow. During Luau generation, penui maps font families and weights to Roblox Font.fromName (including Fredoka One and Montserrat, with bundled font files in library/fonts/) and attaches a matching UIStroke:

local t1 = Instance.new("TextLabel")
t1.BackgroundTransparency = 1
t1.Position = UDim2.fromOffset(89, 22)
t1.Size = UDim2.fromOffset(222, 58)
t1.Text = "Buy 5,000 Coins"
t1.FontFace = Font.fromName("FredokaOne", Enum.FontWeight.Regular, Enum.FontStyle.Normal)
t1.TextColor3 = Color3.fromRGB(255, 255, 255)
local s = Instance.new("UIStroke")
s.Thickness = 4
s.Color = Color3.fromRGB(0, 0, 0)
s.Parent = t1

When your agent overrides text (for example, passing a longer localized string in texts or using text_layout: "card" | "button"), penui's fitLabel estimator calculates grapheme widths and shrinks TextSize and stroke thickness proportionally so preview PNGs and Studio match without overflowing the frame.

5. DRY grid cloning with repeatPositions and f:Clone()

Shop grids, battle pass tiers, and daily reward calendars often repeat the same tile 4, 6, or 12 times. Instead of emitting 6 redundant blocks of Luau or uploading 6 identical images, penui records repeatPositions on repeated components (and alsoFoundIn on units).

When expand_repeats is enabled (the default in manual layout), compose_units and compose_screen instantiate the first item once, then emit a compact REPEAT_OFFSETS table and loop with root:Clone() (or f:Clone()) to place every sibling at its exact Figma offset. Your game scripts can then iterate those named children to populate prices, icons, and click handlers cleanly.

Known Figma conversion boundaries

Deterministic extraction means being explicit about what does not translate 1:1 into static PNGs or Luau. In penui's compiler, Figma NOISE and GRAIN fills are approximated, and BACKGROUND_BLUR as well as angular or diamond gradients are not rendered. Purely decorative effect-layer nodes stay excluded from default search unless explicitly requested.

Frequently asked questions

How does penui handle 9-slice in Roblox Studio when using @2x PNGs?

Roblox SliceCenter is measured in image pixels rather than design pixels. penui multiplies nineSlice.insetPx by the image scale factor (2 for @2x art) when computing Rect.new(...) and sets img.SliceScale = 0.5 so rounded corners retain their exact design-pixel size.

Why are TextLabels editable instead of baked into the button PNG?

Every unit with typography ships a notext.png variant alongside a texts[] metadata array. During composition, penui pairs notext.png on the ImageLabel with real Roblox TextLabel + UIStroke instances so you can change prices, titles, and translations in Luau.

What is imageOrigin in a penui component?

imageOrigin records the negative pixel offset needed when a Figma layer has outer glow or drop-shadow padding extending beyond its logical frame size. Placing the ImageLabel at imageOrigin keeps sibling alignment exact without clipping the glow.

How do repeatPositions work for shop grids and inventory slots?

Repeated tiles store each instance name and coordinate in repeatPositions (or alsoFoundIn for units). With expand_repeats enabled, compose_units and compose_screen build the first tile once and clone it across the grid using a Lua offsets table and Clone().

Install the MCP server · All posts · RSS feed