Hello, I’m trying to make a pet system. But the pets in the chest doesn’t sort in the right order. I’ve even tried to use table.sort() but it didn’t seemed to work.
Here’s the pet list
contains = {
pet_type_1 = 5,
pet_type_2 = 15,
pet_type_3 = 30,
pet_type_4 = 50,
}
Here’s the selecting script:
function getRandomPet(chestStr)
local chest = Chests[chestStr]
local generateChance = math.random(0,1000000) / 10000
local counter = 0
local petSelected = nil
generateChance = 75
table.sort(chest["contains"])
for pet, chance in pairs(chest["contains"]) do
print(pet)
end
end
printing the pet gives these values in order.
pet_type_1
pet_type_4
pet_type_2
pet_type_3
Removing the table.sort doesn’t fix anything.
Can someone please tell why are those listed randomly?