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)
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