Create UI with AI: why deterministic Figma-to-Luau MCP beats prompt generators
Why prompt-only AI UI builders hallucinate coordinates and produce placeholder boxes, and how pre-split layered units with 9-slice insets and editable TextLabels let agents create real UI with AI.
Most attempts to create UI with AI fall into one of two failure modes. Text-to-code generators guess coordinates and emit generic rectangles with arbitrary border radii. Text-to-image generators produce a single flattened PNG that looks appealing as a concept image, yet cannot be clicked, localized, resized across aspect ratios, or wired to live player state.
Building production game interfaces requires a third model: deterministic component assembly over MCP. Instead of asking a language model to invent artwork or geometry from weights, you give the agent a machine-readable catalog of pre-split, designer-made Figma units.
Why prompt-only AI UI generators break in real games
- Hallucinated coordinates and spacing: Language models predict tokens, not pixel grids. Asking for "4 evenly spaced shop cards with 16px margins" routinely yields drifting offsets, clipped labels, or overlapping close buttons.
- Flattened text inside generated images: Image-diffusion UI mockups bake button labels and prices into pixels. You cannot change
"500 Gems"to"1,200 Gems"or bind a player's live coin count in Luau. - No 9-slice or aspect awareness: Stretching a decorative raster card breaks corner bevels and borders unless the engine knows the exact
SliceCenterinset pixels. - Style drift across screens: Generating a shop today and an inventory tomorrow from raw prompts produces two incompatible visual languages.
How deterministic Figma-to-Luau MCP works
penui extracts every screen from real .fig design files into structured, inspectable units before an AI agent ever sees them. Each unit exposes exact metadata rather than vague descriptions:
full.pngandnotext.png: The agent inspectsfull.png(or a 24-tile contact sheet fromsearch_units) to see what the piece looks like, while the Luau compiler bindsnotext.pngbehind live RobloxTextLabels whenever editable typography is present.parts/*.pnglayer decomposition: Sub-layers—such as base panels, inner bevels, stud textures, specular highlights, and badges—are stored separately withzorder and blend metadata so agents can keep or omit layers vialayersparameters.nineSlice.insetPx: Panels and buttons with stretchable centers compile directly toEnum.ScaleType.Slicewith exactRect.new(...)insets andSliceScalecompensation for@2xassets.texts[]typography specs: Exact bounding boxes, alignment, stroke weight, color, and bundled Roblox fonts (Fredoka OneandMontserrat) keep custom copy crisp and centered.repeatPositions: Repeated grid slots and card arrays record every sibling offset socompose_unitsandcompose_screeninstantiate one template and clone the rest withf:Clone().
Inspecting before committing with preview_units
Deterministic generation also means cheap verification. When an agent calls preview_units, penui renders the exact composition—with your overridden button labels, card titles, and scale factor—to a PNG and HTML inspection artifact without touching Roblox Studio or spending metered generation units.
If a title wraps awkwardly or two containers touch, the agent sees the exact bounding boxes and sight-line warnings, adjusts the parameters, and calls compose_units only once the layout is verified.
Native instances when speed matters, bitmaps when art matters
Deterministic Figma tokens also power zero-upload native synthesis. For buttons, panels, headers, tiles, bars, and inputs, the compiler derives UIGradient stops, UICorner radii, and UIStroke widths directly from the Figma palette—letting you ship crisp, dependency-free UI immediately or upgrade hero elements to rbxassetid:// art without rewriting your layout tree.
Frequently asked questions
What makes a deterministic MCP UI server different from an AI UI generator?
A prompt-only generator guesses coordinates, colors, and shapes from scratch. A deterministic MCP UI server like penui serves real Figma-extracted components with exact sizes, 9-slice insets, typography bounds, and repeat offsets so the AI selects and composes proven art.
Are text labels editable when you create UI with AI in penui?
Yes. Units with text ship a text-free notext.png layer paired with a texts[] metadata array describing position, size, color, stroke, and font (Fredoka One or Montserrat). The generated Luau creates real TextLabel instances you can update at runtime.
How does penui prevent repeated shop cards from drifting out of alignment?
Repeated components store exact Figma coordinates in repeatPositions (and alsoFoundIn on units). compose_units and compose_screen build one card and clone siblings via REPEAT_OFFSETS and Clone().
Which AI clients can use penui to create UI with AI?
Any client supporting the Model Context Protocol over stdio or local Streamable HTTP, including Claude Code, Claude Desktop, Cursor, Windsurf, VS Code Copilot, OpenAI Codex, Gemini CLI, Zed, Cline, Roo Code, and Google Antigravity.