Egg hatching system lagging and I can't find why

I made an egg hatching system, but for some reason, it always causes a major lag spike right when the egg hatches, causing the player to have to wait an additional 3 seconds because of lag.

Example:

local ts = game:GetService("TweenService")
local rs = game:GetService("ReplicatedStorage")
local eggs = require(rs:WaitForChild("modules"):WaitForChild("eggs"))
local hatch = rs:WaitForChild("events"):WaitForChild("egg")
local http = game:GetService("HttpService")
local allpetshatchedurl = "https://discordapp.com/api/webhooks/679544252761636909/wOkdALv3vB1h_acaSqQamlGfKMZoi7H-1p6nOjWinNhiG8-OefGS3bekvjQ5Y5dPyIIs"
local cost
local data
local currency
local library = rs:WaitForChild("petlibrary")
local secretpetshatchedurl = "https://discordapp.com/api/webhooks/674765704347779072/gVY5RLjOa7-bzrfa_GUGXuQ1MBODCaorEBq9yGMrPcBocfSMXzi8nnKT203fGnrl9v31"

local totalWeight = 0

local function postNormPet(player,petName,rarity)
	local data = {
		["embeds"] = {{
				["title"] = "Pet Hatched",
				["description"] = "**"..player.."** just hatched a "..rarity.." **"..petName.."**!",
				["color"] = 44543,
    	}}
	}
	local finalData = http:JSONEncode(data)
	http:PostAsync(allpetshatchedurl,finalData)
end

local function legendHatched(player,petName)
	player.PlayerGui.lcan.petName.Value = petName
end

local function secretPetPost(playerName,petName)
	local img
	if petName == "Lord cube" then
		img = "https://www.bing.com/images/blob?bcid=TwIxvWwldgUB6Q"
	end
	local data = {
		["embeds"] = {{
				["title"] = "__**Secret Pet Hatched**__",
				["description"] = "Someone just hatched a **"..petName.."**.",
				["color"] = 44543,
				["thumbnail"] = {
					["url"] = img
				}
    	}}
	}
	local finalData = http:JSONEncode(data)
	http:PostAsync(secretpetshatchedurl,finalData)
end

local function rotateTween(Obj,Rot)
	local ti = TweenInfo.new(.1,Enum.EasingStyle.Linear,Enum.EasingDirection.Out)
	local properties = {
		Rotation = Rot
	}
	local Tween = ts:Create(Obj,ti,properties)
	Tween:Play()
end

local pos = {0,-300,300}

local function ChoosePet(pets)
	for i,v in pairs(pets) do
		totalWeight = totalWeight + v[1]
	end 
	local chance = math.random(1,totalWeight)
	local counter = 0
	for i,v in pairs(pets) do
		counter = counter+v[1]
		if chance <= counter then
			return i
		end
	end
end

local function unboxPet(Player, eggName, multi)
	local pets
	pets = data["Pets"]
	Player.PlayerGui.eg.Enabled = false
	local egs = {}
	local vpeg = {}
	local pcs = {}
	local petmodels = {}
	local num = 1
	if multi == true then
		num = 3
	end
	local txts = {}
	local nb = 0
	local rtys = {}
	Player.PlayerGui.petinv.Enabled = false
	Player.PlayerGui.index.Enabled = false
	local rotz = {0,-30,30}
	local petInv = Player.Pets
	local vps = Player.PlayerGui.hatching:GetChildren()
	for i = 1,num do
	local petChosen = ChoosePet(pets)
	table.insert(pcs,i,petChosen)
	local viewPortTable = Player.PlayerGui.hatching:GetChildren()
	local viewports = {}
	for i,c in pairs(viewPortTable) do
		if c:IsA("ViewportFrame") then
			table.insert(viewports,#viewports+1,c)
		end
	end
	local viewPort = viewports[i]
	local eggClone = workspace.eggs[eggName][eggName]:Clone()
	eggClone.Parent = viewPort
	eggClone:SetPrimaryPartCFrame(CFrame.new(Vector3.new(0,0,0)))
	eggClone:SetPrimaryPartCFrame(CFrame.Angles(0,math.rad(rotz[i]),0))
	eggClone.Name = "egg"
	totalWeight = 0
	table.insert(vpeg,i,eggClone)
	nb = nb + 1
	local cla = Player.PlayerGui.hatching["name"..i]
	cla.Text = pcs[i]
	table.insert(txts,nb,cla)
	nb = nb + 1
	local clb = Player.PlayerGui.hatching["rarity"..i]
	clb.Text = pets[pcs[i]][6]
	table.insert(txts,nb,clb)
	if clb.Text == "Uncommon" then
		clb.TextColor3 = Color3.fromRGB(0,170,255)
		table.insert(rtys,i,"Uncommon")
	elseif clb.Text == "Rare" then
		clb.TextColor3 = Color3.fromRGB(255,170,0)
		table.insert(rtys,i,"Rare")
	elseif clb.Text == "Epic" then
		clb.TextColor3 = Color3.fromRGB(170,0,255)
		table.insert(rtys,i,"Epic")
	elseif clb.Text == "Legendary" or clb.Text == "???" then
		clb.TextColor3 = Color3.fromRGB(0,255,0)
		table.insert(rtys,i,"Legendary")
		legendHatched(Player,pcs[i])
		wait(.2)
	else
		table.insert(rtys,i,"Common")
	end
	if clb.Text == "???" then
		secretPetPost(Player.Name,pcs[i])
	end
	local petClone = library:WaitForChild(pcs[i]):Clone()
	petClone.Parent = Player.PlayerGui.hatching.chosenpets
	petClone:SetPrimaryPartCFrame(CFrame.new(Vector3.new(0,0,0)))
	petClone:SetPrimaryPartCFrame(CFrame.Angles(0,math.rad(rotz[i]+180),0))
	table.insert(petmodels,i,petClone)
	wait(.1)
	end
	for i = 1,num do
		local gui = vps[i]
		gui:TweenPosition(UDim2.new(0,pos[i],0,0),"Out","Bounce",1)
	end
	wait(1)
	local wt = 0.36
	for i = 1,8 do
		for i = 1,num do
		rotateTween(vps[i],25)
		end
		wait(wt)
		wt = wt - 0.02
		for i = 1,num do
		rotateTween(vps[i],-25)
		end
		wait(wt)
		wt = wt - 0.02
	end
	for i = 1,num do
		rotateTween(vps[i],0)
	end
	wait(.1)
	local cams = {}
	for i = 1,num do
		vps[i].egg:Destroy()
		local invp = library:WaitForChild(pcs[i]):Clone()
		invp.Parent = petInv
		table.insert(cams,i,vps[i].cam)
		petmodels[i].Parent = vps[i]
	end
	for i = 1,5 do
		for i = 1,(2*num) do
			txts[i].TextTransparency = txts[i].TextTransparency - 0.2
			wait()
		end
	end
	wait(2)
	for i = 1,num do
		local viewPort = vps[i]
		viewPort:TweenPosition(UDim2.new(0,pos[i],1,0),"In","Linear",1)
	end
	for i = 1,5 do
		for i = 1,(2*num) do
			txts[i].TextTransparency = txts[i].TextTransparency + 0.2
			wait()
		end
	end
	for i = 1,num do
		postNormPet(Player.Name,pcs[i],rtys[i])
	end
	Player.PlayerGui.eg.Enabled = true
	Player.PlayerGui.petinv.Enabled = true
	Player.PlayerGui.index.Enabled = true
	wait(1)
	for i = 1,num do
		for i,c in pairs(Player.PlayerGui.hatching:GetChildren()) do
			if c:IsA("ViewportFrame") then
				c.Position = UDim2.new(0,pos[i],-1,0)
			end
		end
		petmodels[i]:Destroy()
	end
end

hatch.OnServerEvent:Connect(function(user, player, eggname, tpe)
	data = eggs[eggname]
	cost = data["Cost"]
	currency = data["Currency"]
	local stats = user:WaitForChild("leaderstats")
	local cc = stats:FindFirstChild(currency)
	if cc then
		if cc.Value >= cost then
			user.PlayerGui.eg.Enabled = false
			if tpe == "s" then
				cc.Value = cc.Value - cost
				unboxPet(user,eggname)
			elseif tpe == "m" then
				cc.Value = cc.Value - cost*3
				unboxPet(user,eggname,true)
			elseif tpe == "a" then
				local a = false
				local opening = false
				while a == false do
					if opening == false then
						cc.Value = cc.Value - cost*3
						unboxPet(user,eggname,true)
						opening = true
						wait()
						opening = false
					end
					if (user.Character.HumanoidRootPart.Position-workspace.eggs[eggname].buy.Position).Magnitude > 6 then
						a = true
					end
					wait(.1)
				end
			end
			data = nil
			cost = nil
			pets = nil
			currency = nil
			totalWeight = 0
		end
	end
end)

Thank you for your time and support!