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

A ranking type script thingy?

Asked by 7 years ago
Edited 7 years ago

NETWORTH ( works as experience points ) There are specific money bag(tools in game.ServerStorage.Storage)

You don't lose XP, but once you reach a certain amount, you unlock (item)

Is there a better way that I can do this involving a table or something(because this doesn't work past the first one)

stats.NetWorth.Changed:connect(function()
    if networth < 7500 then
            givebag(p, "Starter Money Bag", "none") -- player, bag, removebagtype
    elseif networth < 50000 and networth > 7500 then
            givebag(p, "Rookie Money Bag", "Starter Money Bag")
    end 
end)

1 answer

Log in to vote
0
Answered by 7 years ago

Here is something I came up with. As long as you list the ranks in order (ascending), updateRank() will keep track of which rank you're on and automatically call givebag() when a change in rank is detected.

local p = ...
local currentRank
local ranks = -- Array of ranks, in ascending order
{
    {
        NetWorth = 0,
        Bag = "Starter Money Bag",
    },
    {
        NetWorth = 7500,
        Bag = "Rookie Money Bag",
    },
    {
        NetWorth = 50000,
        Bag = "Another Money Bag",
    }
}

local function givebag(player, bag, removebagtype)
    ...
end

local function updateRank(currentNetWorth)
    local rank
    for _, r in ipairs(ranks) do
        if r.NetWorth > currentNetWorth then
            break
        end
        rank = r
    end
    if rank ~= currentRank then
        local _, lastBag = pcall(function() return ranks[i-1].Bag  end)
        local bag = rank.Bag
        givebag(p, bag, lastBag or "none")
        currentRank = rank
    end
end

stats.NetWorth.Changed:connect(updateRank)
updateRank(stats.NetWorth.Value) -- Update right away
0
You're a life saver. I appreciate it very much. getzedotus 0 — 7y
0
Any chance you can add me on discord? brandon#1169 getzedotus 0 — 7y
0
I'm in the Scripting Helpers Discord server from time to time. gwest2#4333 WillieTehWierdo200 966 — 7y
Ad

Answer this question