#Rarity Chance Fixing

1 messages · Page 1 of 1 (latest)

jolly halo
#

Okay so i have a rarity system but i dont understand how i can actually have a accruate "1 in 125" system because the rarity i put for example the easiest pet as 45, is not a 1 in 45, should be a 1 in 1 right?

local ColorChances = {
    -- COLOR, CHANCE, CHANCE NAME
    {Color3.fromRGB(255, 0, 0), 40, "Common"};
    {Color3.fromRGB(0, 255, 0), 30, "Rare"};
    {Color3.fromRGB(0, 0, 255), 10, "Epic"};
}```
```lua
function ColorChances.getRandomIndex(self)
    local totalChance = 0
    for _, v in ipairs(self) do
        totalChance = totalChance + v[2]
    end

    local randomNum = math.random() * totalChance

    local accumulated = 0
    for i, v in ipairs(self) do
        accumulated = accumulated + v[2]
        if randomNum <= accumulated then
            return v
        end
    end

    return self[1]
end```
#

so pretty much im just asking how i can convert these chances to chances that make sense

delicate solstice
#

you could do

local rarity = totalChance / v[2]
print("1 in "..rarity)

If it for example 40, it will result 1 in 2.5

Unless u want do include 1 in 1, which you have to change to

1, "Common",  -- 1 in 1
50, "Rare"  -- 1 in 50
100, "Epic" -- 1 in 100

then you do

local weight = 1 / v[2]