Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Redemption Code Help?

Asked by
22To 70
9 years ago

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
0
Can you tell us what the error is and which line(s)? PiggyJingles 358 — 9y
0
no i basically wants to kno how can i add leaderboard to it like when they redeem it they will get points 22To 70 — 9y
0
People thumbs down because they dont understand the ycan just ask 22To 70 — 9y

Answer this question