This inserts the pets chance into a table where it will get a random one. The chance is the number next to the pets name (Code Block 2 for the module/pets)
local canGetPets = {}
local rar = eggModule[egg].Rarities
for currentPlace = 1,#rar do
local mathmatical = math.max(rar[currentPlace][2])
for i = 1,mathmatical do
table.insert(canGetPets, rar[currentPlace][1])
end
end
(Egg module script with pets and their chance)
local eggs = {
["Basic Egg"] = {
Cost = {"Cash", 0};
Rarities = {
{"Dog", 55};
{"Cat", 45};
{"Bear", 30};
{"Wolf", 15};
{"Vespertillius", 0.002};
}
};
}
return eggs
The problem is is that it can't insert 0.002 of a pet into a table (obviously) I just don't know how else to do it.

9 comments
Is the number supposed to be a percentage?
Yes it is
Maybe you can use some smart mathing, like for example let's say you got 20% on a pet, it would make sense to do math.random(1, 5), and check if its 2 for example, that'sa logicall way to do it, cuz math.random(1, 5) has a 20% chance of returning 2, its pretty much trying to use fractions
math.random(100) or math.random(1,100) would do (first selects number 0-100, second selects number 1-100)
45+55+30+15+0.02 is bigger than 100
you can multiply everything by 100
@loganboyinco yah maybe, thats a cool idea
If I multiply it by the amount that it take for the decimal to become 1, it will lag, a lot
Came back to say the problem was that I was printing causing an overload in the output, causing lag. Thanks for the help though