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

[FOUND SOLUTION] Are these pet chances broken? (pet system)

Asked by
Gogulsky 129
4 years ago
Edited 3 years ago

I feel like there's something wrong with the local Chance. People have been reporting that the pets that are under 1% are very hard to hatch. If I make it (0,TotalWeight) I'm pretty sure it won't work. Anyone can tell me if it's broken?

function ChoosePet(Egg)
    local Data = Eggs[Egg]
    local Pets = Data["Pets"]
    local TotalWeight = 0
    for i,v in pairs(Pets) do
        TotalWeight = TotalWeight + v.Rarity
    end
    local Chance = math.random(1,TotalWeight)
    local Counter = 0
    for i,v in pairs(Pets) do
        Counter = Counter+v.Rarity
        if Counter >= Chance then
            return v.Name
        end
    end
end
0
Try increasing the weight cherrythetree 130 — 4y
0
I already did. I changed it to 1 and it didn't do anything, changed it to 10 and the results were the same, changed it to 100 and the eggs gained a very long cooldown between the next hatch. Gogulsky 129 — 4y
0
The real problem is the local Chance. The math.random(1,TotalWeight) - i think what it does is starts from 1% and it's supposed to start from 0 but I can't put 0 in math.random since that won't work. Gogulsky 129 — 4y

Answer this question