local baseRarityTable = {}
local luckRarityTable = {}
local subtractTable = {}
local totalWeight = 0
local luck = player:FindFirstChild("OtherStats"):FindFirstChild("Luck").Value
for i, pet in pairs(RS.Pets[egg]:GetChildren()) do
baseRarityTable[pet.Name] = pet.Rarity.Value
totalWeight += pet.Rarity.Value
end
local numberOfNonRarePets = 0
for pet, chance in pairs(baseRarityTable) do
if chance >= 10 then
numberOfNonRarePets += 1
else
chance *= luck
table.insert(subtractTable,chance-(RS.Pets[egg]:FindFirstChild(pet).Rarity.Value))
end
luckRarityTable[pet] = chance
end
for pet, chance in pairs(baseRarityTable) do
if chance >= 10 then
for i, subtractAmount in ipairs(subtractTable) do
chance -= subtractAmount/numberOfNonRarePets
end
end
end
This is what I made to figure out luck, but it is messy and hard to follow. Is there a more efficient way?