Chance based pet system help

I’m creating a new game and I’m working on my pet system and I can’t get the % system working, Does anyone knows have to fix it?

ReplicatedStorage.Remotes.Egg.Select.OnServerEvent:Connect(function(Player, ViewportFrame, EggAsset)
	print(Player.Name.." Is About To Get A Pet!")
	local EggID = EggAsset.Name
	ViewportFrame:Destroy()
	local EggID_RarityTable = RarityTable[EggID]
	
	local MaxNumber = 0
	
	for _, v in pairs(EggID_RarityTable) do
		MaxNumber += v
	end
	
	local RandomNumber = math.random(1, MaxNumber)
	local closest
	for name, chance in pairs(EggID_RarityTable) do
		if RandomNumber <= chance then
			print(tostring(RandomNumber.." = "..chance))
			closest = name
			return
		else
			RandomNumber -= chance
		end
	end

	
	local PetFolder = Player:WaitForChild("leaderstats"):WaitForChild("Pets")
	local IntValue = Instance.new("IntValue", PetFolder)
	IntValue.Name = closest
	IntValue:SetAttribute("PetName", closest)
	IntValue.Value = 1 -- Pet Level
end)

RarityModule

return {
	
	Test = {
		TestPet = 10,
		TestPet2 = 50,
	}
	
}

Sorry, here to mention you absolutely should not be calling destroy on a variable the client can choose, someone can destroy your game by firing Select with these args
Select:FireServer(whateveryouwanttodelete, {Name = “troll”})

What’s going on? are you getting any results? I’m confused on how the random chance is supposed to work… Could you tell me what your intentions were?

Replacing return with a break should fix it