Pets randomly disappear (Scripting issue)

Hii! I’m messing around with this a lot and no idea why all of this happens, in the thousands of tests we did everything worked perfectly. Some players when buy a new pet it doesn’t apprear, something here is wrong?

–all of the scripts are serversided
– Buying an normal egg

PetName = GetChance(Petworld,playerData.Gamepasses.x3LuckyPets.Value)	-- get the name of a pet randomly choosed from player's stage

game.ReplicatedStorage.Sv.Wait4Anim:Fire(player)	-- block new purchases for 5 seconds due the cracking egg animation

local ID = playerPetsFol.ID.Value	-- the new unique ID

local newmoney = playerData.Diamonds.Value - price
local final = math.floor(newmoney + 0.5)
														-- his new money
local DiamondsStore = DataStore2("Diamonds",player)	
DiamondsStore:Set(final)

player.PlayerGui.HUD.Frame.Diamonds.Num.Text = ab:ab(playerData.Diamonds.Value)	-- update his money in the HUD
----------------------------------------------------
local newPet = petsFolder[PetName]:Clone()
newPet.Parent = Storage							-- the new pet to his storage
newPet.Name = ID
newPet.ID.Value = ID

game.ReplicatedStorage.Sv.Hatch:Fire(player,buy3,newPet,Petworld)	-- launch the egg animation 

playerPetsFol.ID.Value = playerPetsFol.ID.Value + 1		-- next unique ID ready


–This is the “GetChance” function:

local function getTable(Zone)	-- (Summarized) returns a table with the pets of that zone and they probabilities

	local Egg1 = {
		{"Chicken", 1},
		{"Pig", 8},
		{"Rabbit", 10},
		{"Cat", 20},
		{"Dog", 25},
		{"Fish",36}
	}
	
	return Egg1
end

local percent = (math.random(0,10000)) / 100	-- random percent between 0.1 and 100

local current = 0
local default
local chances = getTable(Zone)	-- Get the table with the pets of that zone and they probabilities

for i, v in ipairs(chances) do	-- Choose the correct pet Name
	if v[2] then
		if (v[2]+current) >= percent then
			return v[1]
		else
			current += v[2]
		end
	else
		default = v[1]
	end
end
return default	-- Return it to PetName as his new pet

The bug reports I receive are that they buy pets and the animation doesnt show, like the pet, it doesnt appear in the pet backpack. But the most scary thing is that for some reason sometimes when they buy a pet or upgrade it (as I show you down there) THE ENTIRE STORAGE GET ERASED!! Something happens and they loose all they pets, even the robux one because they are all in his storage folder (of course I don’t have nothing like, if something happens delete all his storage, thats dumb)


–Upgrade system: 5 Normal pets = 1 Shiny… 3 Shinys = 3 Demonic

local RequiredPetAmount = 5				-- this is obvious
if petFolder.Type.Value == "Shiny" then RequiredPetAmount = 3 end

if petFolder.CanUpgrade.Value == false then return end	-- if its demonic it cant be upgraded

for i, pet in pairs(storage:GetChildren()) do

	if pet.ScriptName.Value == PetName and Amount < RequiredPetAmount then 	-- if the player has the required amount of pets
		Amount = Amount + 1 
		ids[Amount] = pet.ID.Value				-- store it in this table
		tipe = pet.Type.Value
	end
end

if Amount >= RequiredPetAmount then	-- upgrade ready
	local upgradeo = false
	local newPet = nil

	if petFolder.Type.Value == "Shiny" then	-- gonna be demonic (2th upgrade)
		upgradeo = true

		for i, folder in pairs(game.ServerStorage.Pets.Values.Demonic:GetChildren()) do

			if string.find(petFolder.ScriptName.Value,folder.Name) then				
				newPet = folder:Clone()
				break
			end

		end

	elseif petFolder.Type.Value == "Demonic" then	-- its demonic, not upgradeable


	else	-- normal pets, gonna be shinys (first upgrade)
		upgradeo = true
		newPet = game.ServerStorage.Pets.Values.Shiny[PetName]:Clone()

	end

	if upgradeo == true and newPet ~= nil then

		newID = PlayerPetFolder.ID.Value	-- creating the new pet
		newPet.Parent = storage
		newPet.Name = newID
		newPet.ID.Value = newID

		PlayerPetFolder.ID.Value = PlayerPetFolder.ID.Value + 1
		PetManager(player,"DeleteMultiple",0,ids)				-- delete the required pets

	end

else	
	-- dont have the required amount of pets
end

game.ReplicatedStorage.Sv.LocalPetFolderUpdater:Fire(player)	--update all of this in the local folders

wait(0.1)

game.ReplicatedStorage.Remotes.ToLocal:FireClient(player,"UpdatePetInv")	-- update pet inventory (with the new folder where the required pets doesnt exist anymore and there is the upgraded one)
wait()		
game.ReplicatedStorage.Remotes.ToLocal:FireClient(player,"SelectPet",newID)	-- select it automaticly

Some reports:
I played the game and bought some eggs and when I left and came back I only had my three equipped pets. All the rest are gone. And now when I buy an egg the pet doesn’t show up in my inventory.

I bought 2 pets which showed up in my inventory and now every time I buy a pet it doesn’t go into my inventory. I have bought 6 more eggs and got nothing. :frowning: