Hello, I’m currently working on a game that needs a rarity system, but I’ve encountered a problem.
Basically to keep it short, the function will find a random rarity, and then find another and another rarity, and the last rarity it picks is the one that the player gets (usually more uncommon rarities)
For example we have the source code right here:
local RS = game. ReplicatedStorage
local BG - RS. BillboardGui
local Rarity - BG. Rarity
local multipliersArray - {
Common = 0.50
Uncommon - 0.35,
Rare - 0.10,
Epic -0.05,
Legendary -0.01,
Mythic - 0.001
}
local function chooseIndex(multipliersArray)
local weightedSum = 0
for i,v in pairs(multipliersArray) do
weightedSum += V
end
local random = Random.new()
local rnd - random:Next Number(0, weightedSum)
for i,v in pairs(multipliersArray) do if rnd <V then
Rarity.Value = i
print(i)
end
rnd -= v
end
end
choose Index(multipliersArray)
And it will print out:
But it will only use the last one, as I stated, so it picks Rare, not Uncommon. I only want it to pick once though, so how can I achieve this?