CyberMax
CyberMax › Answers

How to make a codes system in Roblox (redeem codes)

Updated 2026-10-17 · Roblox and game developers · by CyberMax

Short answer

Keep the codes in a server-only table with a reward and an expiry time, normalise what the player types (trim, uppercase), check that the code exists, isn't expired and isn't in the player's saved list of used codes, then grant the reward and add the code to that list.

Copy-paste code

ServerScriptService/Codes.server.lua

local CODES = {
	RELEASE = { coins = 500, expires = os.time({ year = 2026, month = 12, day = 31, hour = 23 }) },
	THANKYOU = { coins = 250 },
}

local function redeem(data, typed)
	local code = string.upper((string.gsub(typed or "", "%s", "")))
	local c = CODES[code]
	if not c then return false, "Invalid code" end
	if c.expires and os.time() > c.expires then return false, "This code has expired" end
	data.usedCodes = data.usedCodes or {}
	if data.usedCodes[code] then return false, "Already redeemed" end
	data.usedCodes[code] = true
	data.coins = (data.coins or 0) + c.coins
	return true, "+" .. c.coins .. " coins"
end

game.ReplicatedStorage.RedeemCode.OnServerInvoke = function(player, typed)
	if typeof(typed) ~= "string" or #typed > 30 then return false, "Invalid code" end
	local data = profiles[player]
	if not data then return false, "Loading" end
	return redeem(data, typed)
end

Good to know

Keep CODES in a server Script or ServerStorage module so exploiters can't read the list.

Rate-limit the RemoteFunction (for example, one try per second per player) so nobody can brute-force codes.

Studwright: Roblox systems that never lose saves

from $12

Studwright includes a tested Codes module and RemoteGuard (rate limits and argument checks for remotes), plus 14 more systems.

Secure checkout · 14-day fix-or-refund if it doesn't work as described (terms)

Questions

Can I add codes without updating the game?

Yes, store them in a DataStore or MemoryStore and read them on server start, but keep the same checks.

Why uppercase?

So "release", "Release " and "RELEASE" all work.

Free: the Roblox Starter Kit

7 free Luau modules (damage, pets, shop formatting, admin audit log, tycoon guards and more) plus 3 free calculators, then 5 short emails with the scripting fixes we see go wrong most often.

You get one email to confirm first. Then the kit, and 5 short emails over two weeks. One-click unsubscribe in every email; we never share your address.

Related answers

Roblox daily rewards script with a login streakA server-side daily reward and streak script for Roblox: UTC day numbers, a streak that resets after a missed A Roblox DataStore save script that never wipes player dataCopy-paste Luau for loading and saving player data with DataStoreService: retries, UpdateAsync, BindToClose an