Roblox GUI Maker logoRoblox GUI Maker
Unofficial third-party tool · Not affiliated with Roblox Corporation

Roblox Lua GUI Code Snippets: Copy-Paste Reference (2026)

2026-07-21 · Roblox GUI Maker Team

Create a ScreenGui programmatically

The foundation of every GUI. Create the ScreenGui, set its properties, and parent it to PlayerGui. ResetOnSpawn = false keeps the GUI alive across respawns so it does not vanish when the player dies and respawns. IgnoreGuiInset = true pushes the GUI under the top bar instead of leaving a gap, which matters for full-screen menus. Always parent the ScreenGui to PlayerGui, never to workspace or StarterGui at runtime, or it will not render on the player's screen.

StarterGui (LocalScript)
lua
1local Players = game:GetService("Players")
2local player = Players.LocalPlayer
3
4local screenGui = Instance.new("ScreenGui")
5screenGui.Name = "MyGui"
6screenGui.ResetOnSpawn = false
7screenGui.IgnoreGuiInset = true
8screenGui.Parent = player:WaitForChild("PlayerGui")

Add a Frame and TextLabel

A centered panel with a title. Use Scale-based sizing and AnchorPoint for true centering so the panel sits in the middle of any screen. AnchorPoint moves the reference point from the top-left corner to the center of the element, which means Position (0.5, 0, 0.5, 0) places the panel's center at the screen's center instead of its top-left corner. Skip AnchorPoint and your centered panel will drift down and to the right on larger screens.

Add to ScreenGui
lua
1local panel = Instance.new("Frame")
2panel.Size = UDim2.new(0.4, 0, 0.3, 0)
3panel.Position = UDim2.new(0.5, 0, 0.5, 0)
4panel.AnchorPoint = Vector2.new(0.5, 0.5)
5panel.BackgroundColor3 = Color3.fromRGB(30, 30, 40)
6panel.Parent = screenGui
7
8local title = Instance.new("TextLabel")
9title.Size = UDim2.new(1, 0, 0.3, 0)
10title.BackgroundTransparency = 1
11title.Text = "Hello Roblox"
12title.TextColor3 = Color3.fromRGB(255, 255, 255)
13title.TextScaled = true
14title.Parent = panel

Clickable button with feedback

A TextButton that runs a function on click, with a quick press animation for tactile feedback. Connect MouseButton1Click to a function that fires a RemoteEvent to the server for any game action, never trusting the client to decide game state directly. A press animation that scales the button down 5 percent for a tenth of a second makes the click feel responsive, and it costs one extra tween, so it is worth adding to every button.

Button with press animation
lua
1local button = Instance.new("TextButton")
2button.Size = UDim2.new(0.5, 0, 0.4, 0)
3button.Position = UDim2.new(0.25, 0, 0.4, 0)
4button.BackgroundColor3 = Color3.fromRGB(109, 93, 251)
5button.Text = "Click Me"
6button.TextScaled = true
7button.Parent = panel
8
9button.MouseButton1Click:Connect(function()
10 print("Button clicked!")
11 -- Fire a RemoteEvent to the server for game actions
12end)

TweenService: smooth animation

Animate any GUI property smoothly. The most common pattern is sliding a panel in from off-screen or fading it out. TweenService:Create takes the element, a TweenInfo with a time and easing style, and a table of target property values, then :Play() runs the animation at 60 frames per second. Animate Size, Position, BackgroundTransparency, or BackgroundColor3 depending on the effect you want, and chain tweens with Completed for multi-step motion.

TweenService slide-in
lua
1local TweenService = game:GetService("TweenService")
2
3panel.Position = UDim2.new(0.5, 0, 1.5, 0) -- start off-screen
4local tween = TweenService:Create(
5 panel,
6 TweenInfo.new(0.4, Enum.EasingStyle.Quint, Enum.EasingDirection.Out),
7 { Position = UDim2.new(0.5, 0, 0.5, 0) }
8)
9tween:Play()

DataStore: save and load

Persist player data across sessions. Always wrap DataStore calls in pcall to handle failures gracefully, because Roblox throttles DataStore requests and a failed GetAsync or SetAsync should never crash your game. Load data on PlayerAdded and save on PlayerRemoving as a baseline, and use UpdateAsync instead of SetAsync when multiple servers might write the same key, since UpdateAsync reads the current value before writing and avoids clobbering concurrent updates.

ServerScriptService (Script)
lua
1local DataStoreService = game:GetService("DataStoreService")
2local Players = game:GetService("Players")
3local store = DataStoreService:GetDataStore("PlayerData")
4
5local function loadData(player)
6 local success, data = pcall(function()
7 return store:GetAsync(player.UserId)
8 end)
9 return (success and data) or { coins = 0 }
10end
11
12local function saveData(player, data)
13 pcall(function()
14 store:SetAsync(player.UserId, data)
15 end)
16end
17
18Players.PlayerAdded:Connect(function(player)
19 local data = loadData(player)
20 print(player.Name, "loaded:", data.coins)
21end)

UIGridLayout: auto-arranged grid

Arrange child elements in a grid automatically. Perfect for inventories, shops, and item lists, where the number of items changes at runtime. Set CellSize and CellPadding once, parent the UIGridLayout to a ScrollingFrame, and every Frame you add afterward slots into the grid without manual positioning. Use Scale in CellSize if you want cells to resize with the screen, or Offset for fixed-size slots that stay a set number of pixels.

Grid layout
lua
1local grid = Instance.new("UIGridLayout")
2grid.CellSize = UDim2.fromOffset(120, 140)
3grid.CellPadding = UDim2.fromOffset(8, 8)
4grid.FillDirection = Enum.FillDirection.Horizontal
5grid.SortOrder = Enum.SortOrder.LayoutOrder
6grid.Parent = itemContainer
7
8-- Every Frame you parent to itemContainer now arranges in a grid automatically

UIListLayout: vertical stack

Stack elements vertically (or horizontally) with consistent spacing. The standard way to build menus and lists.

List layout
lua
1local list = Instance.new("UIListLayout")
2list.FillDirection = Enum.FillDirection.Vertical
3list.Padding = UDim.new(0, 12)
4list.HorizontalAlignment = Enum.HorizontalAlignment.Center
5list.SortOrder = Enum.SortOrder.LayoutOrder
6list.Parent = menuContainer

Frequently asked questions