Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

A ranking type script thingy?

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

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

3 comments

0

You're a life saver. I appreciate it very much.

0

Any chance you can add me on discord? brandon#1169

0

I'm in the Scripting Helpers Discord server from time to time. gwest2#4333

This discussion is preserved as it was. New answers, comments, and votes are closed.