How to make a codes system in Roblox (redeem codes)
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)
endGood 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 $12Studwright 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.