local cost = 800
local petModule = require(game.ServerScriptService:WaitForChild("PetModule"))
script.Parent.ClickDetector.MouseClick:Connect(function(player)
if player.leaderstats.BugCoins.Value >= cost then
player.leaderstats.BugCoins.Value = player.leaderstats.BugCoins.Value - cost
local pet = petModule.chooseRandomPet()
print(pet.Name.." selected")
game.ReplicatedStorage.HatchEgg:FireClient(player,pet)
end
end)
I think there is an issue because your math.random(1,100) is greater than the sum of you rarities in the table. You table has a total weight of 79, but you are trying to loop through your table which doesn’t even add to 100. What you’re trying to do is check for a random number between 1 100, and if <= then it selects that., but because your rarities don’t add to 100, if the number is greater than that, there would be an error. I might be wrong but consider changing it match to your weighted rarities. Otherwise, it could a problem with your chosen pet.