I made some code and code module but i wan to make it able to add mney to the leaderboard when they redeem it i tried but i ended up breaking the whole script
Module:
local codes = { ["supercode"] = function(player) print(player.Name .. " entered a code!") end, ["examplecode"] = function(player) print("this example code was redeemed by " .. player.Name) end, ["mlg_swag_360"] = function(player) print(player.Name .. " is mlg!!!1!11!") end } return(codes)
Script:
local codes = require(game.ServerStorage.Codes) local usedCodes = game:GetService("DataStoreService"):GetDataStore("UsedCodes") local function IsInTable(t, thing) for i, v in pairs(t) do if v == thing then return(true) end end return(false) end game.Players.PlayerAdded:connect(function(player) if player.userId > 0 then local pCodes = usedCodes:GetAsync("user_" .. player.userId) if not pCodes then usedCodes:SetAsync("user_" .. player.userId, {}) end end end) function game.ReplicatedStorage.RedeemCode.OnServerInvoke(player, code) if player.userId > 0 then code = string.lower(code) if codes[code] then local pCodes = usedCodes:GetAsync("user_" .. player.userId) if pCodes then if not IsInTable(pCodes, code) then table.insert(pCodes, code) usedCodes:SetAsync("user_" .. player.userId, pCodes) codes[code](player) return true, "Success!" else return false, "You've already redeemed that code." end end else return false, "Invalid code." end end return false, "Sorry, guests can't redeem codes." end