Template · codes
Roblox codes GUI template
A redeem panel: text box, REDEEM button and a lookup table, wired so you can see exactly where your own codes and rewards go.
What this codes template builds
The shortest of the six panels — 0.34 x 0.26 of the screen — with a Codes title, a grey hint line, a TextBox with the placeholder CODE..., and an accent-coloured REDEEM button sitting to its right. Underneath them, a table of three codes and a click handler that reads the box, upper-cases the text and looks it up.
The two controls are sized so the row adds up exactly: 16 pixels of left margin, then the box at UDim2.new(1, -104, 0, 34), then a 4-pixel gap, then 68 pixels of button, then 16 pixels of right margin. That is where the -104 comes from — 20 for the gap, button and margin beyond what the box needs. Change the button width and you change the box width with it.
The code
local panel = Instance.new("Frame")
panel.Name = "CodesPanel"
panel.AnchorPoint = Vector2.new(0.5, 0.5)
panel.Position = UDim2.fromScale(0.5, 0.5)
panel.Size = UDim2.fromScale(0.34, 0.26)
panel.BackgroundColor3 = Color3.fromRGB(24, 27, 33)
panel.BorderSizePixel = 0
panel.Parent = screenGui
local hint = Instance.new("TextLabel")
hint.Name = "Hint"
hint.BackgroundTransparency = 1
hint.Position = UDim2.fromOffset(16, 42)
hint.Size = UDim2.new(1, -32, 0, 18)
hint.Font = Enum.Font.Gotham
hint.TextSize = 12
hint.TextXAlignment = Enum.TextXAlignment.Left
hint.TextColor3 = Color3.fromRGB(154, 163, 178)
hint.Text = "Enter a code from the game page."
hint.Parent = panel
local box = Instance.new("TextBox")
box.Name = "CodeBox"
box.Position = UDim2.fromOffset(16, 68)
box.Size = UDim2.new(1, -104, 0, 34)
box.BackgroundColor3 = Color3.fromRGB(31, 36, 45)
box.BorderSizePixel = 0
box.Font = Enum.Font.Gotham
box.TextSize = 14
box.TextColor3 = Color3.fromRGB(230, 233, 239)
box.PlaceholderText = "CODE..."
box.ClearTextOnFocus = false
box.Parent = panel
local boxCorner = Instance.new("UICorner")
boxCorner.CornerRadius = UDim.new(0, 4)
boxCorner.Parent = box
local boxPad = Instance.new("UIPadding")
boxPad.PaddingLeft = UDim.new(0, 8)
boxPad.Parent = box
local redeem = Instance.new("TextButton")
redeem.Name = "Redeem"
redeem.Position = UDim2.new(1, -84, 0, 68)
redeem.Size = UDim2.fromOffset(68, 34)
redeem.BackgroundColor3 = Color3.fromRGB(70, 214, 138)
redeem.BorderSizePixel = 0
redeem.Font = Enum.Font.GothamBold
redeem.TextSize = 12
redeem.TextColor3 = Color3.fromRGB(10, 16, 12)
redeem.Text = "REDEEM"
redeem.Parent = panel
local redeemCorner = Instance.new("UICorner")
redeemCorner.CornerRadius = UDim.new(0, 4)
redeemCorner.Parent = redeem
local codes = { WELCOME = 100, LAUNCH = 250, UPDATE = 50 }
redeem.MouseButton1Click:Connect(function()
local code = string.upper(box.Text)
if codes[code] then
box.Text = ""
print("Redeemed", code, codes[code]) -- replace with your reward logic
end
end)
That is the codes panel. The full script the maker copies also creates the ScreenGui, the title label and the X close button.
Never ship the table on the client
What you are looking at is a preview: the table lives inside the LocalScript. Anything in a LocalScript can be read by whoever joins your game, so in a real game the code list must move to ServerScriptService and the client only sends what the player typed.
-- ServerScriptService/RedeemService (a Script, not a LocalScript)
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local codes = { WELCOME = 100, LAUNCH = 250, UPDATE = 50 }
local used = {}
local redeem = Instance.new("RemoteEvent")
redeem.Name = "RedeemCode"
redeem.Parent = ReplicatedStorage
redeem.OnServerEvent:Connect(function(player, raw)
if type(raw) ~= "string" then return end
local code = string.upper((string.gsub(raw, "%s+", "")))
local amount = codes[code]
if not amount then return end
used[player.UserId] = used[player.UserId] or {}
if used[player.UserId][code] then return end
used[player.UserId][code] = true
player.leaderstats.Coins.Value += amount
end)
Three details in those ten lines matter more than the rest:
type(raw) ~= "string"— a remote can be called with a number, a table or nothing. Check before you index.string.upperplusgsub("%s+", "")— players pastewelcomeoff a Discord post with a stray space, and it should still work.used[player.UserId][code]— one redemption per player per code. Without it, the same player can spam the button.
The client side becomes one line:
redeem.MouseButton1Click:Connect(function()
game:GetService("ReplicatedStorage"):WaitForChild("RedeemCode"):FireServer(box.Text)
end)
Surviving a rejoin, and telling the player what happened
used lives in memory, so closing the game resets it and every code works again. Wrap it in a DataStore:
local store = game:GetService("DataStoreService"):GetDataStore("Codes")
-- on PlayerAdded: used[player.UserId] = store:GetAsync("u_" .. player.UserId) or {}
-- after a successful redeem: store:SetAsync("u_" .. player.UserId, used[player.UserId])
For feedback, add a TextLabel under the box and have the server fire back Redeemed 250 coins or That code is not valid on a second RemoteEvent — a silent button is the most common complaint about hand-built redeem panels. Clear box.Text only after the server says the code worked, otherwise a mistyped code wipes what the player typed.
This panel needs a different size on phones
0.34 of a 390-pixel phone screen is 133 pixels wide. Take away 16 of left margin, 68 of button and 16 of right margin and the text box is left with 33 pixels — unreadable, and the placeholder will not even fit.
Use a fixed offset instead of a fraction for this one:
panel.Size = UDim2.fromOffset(320, 180)
320 still fits a 390-pixel screen with 35 pixels to spare each side, and every control keeps its size at every resolution. The other five templates scale down acceptably; this is the one that has to be measured in pixels.
Related layouts
Settings GUI template — the other utility panel, built the same way
Shop GUI template — where the coins this panel grants usually get spent
Open the maker to rebuild this with a different accent or corner
FAQ
Does this need a DataStore? Only if a code should work once per player. In-memory used is enough for a code that is valid for the first hundred players, or for testing.
Does the box care about capital letters? No. The handler upper-cases whatever is typed, so welcome and WELCOME both match the table key.
How many codes can I have? The table has no practical limit — a few hundred entries cost nothing to look up. Keep them on the server and delete expired ones when the event ends.
Can I use it in a paid game? Yes. The code is yours, no licence fee, no attribution.