This has been a problem for many people including me. The local Chance doesn't make the pets under 1% hatchable. The 1 in math.random(1,TotalWeight) would need to be 0 but it won't work.

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

This script is from the better pet system. However there's another pet system that has working pet chances, it basically has a math.random(1,TotalWeight) too however it also has this:

if Chance <= Counter then
				return i

Both of these pet systems obviously work differently. The "i" are the suffixes and I believe that this is what makes the pets under 1% hatchable. I still don't know how to make this possible in the other pet system. Any help?

4 comments

0

I think it is because math.random does not go into decimals by itself, the way I get math.random with decimals is do something like math.random(0,100)/100

0

Looking at this, its half way down, math.random returns a decimal value between 0 and 1, multiply this by some value and this will give you a value between 0 and some value. This should fit you case. https://developer.roblox.com/en-us/api-reference/lua-docs/math

0

A use Case: math.randomseed(math.random()*math.random) local Chance = math.random() * 100 if chance <= counter then return v.Name

0

Please remember to use math.randomseed so that your pet system is not susceptible to RNG manipulation!