Help with trade system

can u help me make this work with a table so basically i have something that updates the players inventory but it has to be called


_G.newTemplate = function(petName)
	local pet = replicatedStorage.Pets:FindFirstChild(petName)
	local newTemplate = template:Clone()
	newTemplate.Name = petName
	newTemplate.Parent = container
	
	local viewPortFrame = Module3D:Attach3D(newTemplate.Display, pet:Clone(), 4)
	if pet:GetAttribute("Rarity_Name") == "Huge" then
		viewPortFrame:SetDepthMultiplier(0.95)
	else
		viewPortFrame:SetDepthMultiplier(1.2*(pet:GetAttribute("SizeHatch")-1.25))
	end
	viewPortFrame.Camera.FieldOfView = 5
	viewPortFrame.Visible = true
	viewPortFrame.Ambient = Color3.fromRGB(255, 255, 255)
	viewPortFrame.LightColor = Color3.fromRGB(255, 255, 255)
	
	if pet:GetAttribute("Rarity_Name") == "Huge" then
		newTemplate:WaitForChild("TextLabel").Text = "???"
		newTemplate:WaitForChild("Hugemark").Visible = true
	else
		newTemplate:WaitForChild("TextLabel").Text = "x"..tostring(pet:GetAttribute("Multiple_Clicks"))
		newTemplate:WaitForChild("Hugemark").Visible = false
	end
	newTemplate:WaitForChild("TextLabel").TextColor3 = pet:GetAttribute("Rarity_Color")
	
	runService.RenderStepped:Connect(function()
		viewPortFrame:SetCFrame(CFrame.Angles(0,tick() * 2 % (math.pi * 2),0) * CFrame.Angles(math.rad(-10),0,0))
	end)
	
	newTemplate.MouseButton1Click:Connect(function()

		if MultiDeleteButton:GetAttribute("active") == true then
			if newTemplate:GetAttribute("Delete") == false then
				if newTemplate:GetAttribute("Equipped") == true then
				else
					newTemplate:SetAttribute("Delete", true)
				end
			else
				newTemplate:SetAttribute("Delete", false)
			end
		else
			if newTemplate:GetAttribute("Equipped") == true then
				replicatedStorage:WaitForChild("EggRemoteEvents"):WaitForChild("UnEquipPet"):InvokeServer(pet.Name)
				newTemplate:SetAttribute("Equipped", false)
				sort(newTemplate)
			else
				local numberOfPetsEquipped = #WorkSpace:WaitForChild("Player_Pets"):WaitForChild(player.Name):GetChildren()

				if (numberOfPetsEquipped + 1) <= player:WaitForChild("Values"):WaitForChild("MaxPetsEquipped").Value then
					local clonedPet = pet:Clone()

					replicatedStorage:WaitForChild("EggRemoteEvents"):WaitForChild("EquipPet"):InvokeServer(pet)
					newTemplate:SetAttribute("Equipped", true)
					sort(newTemplate)

					return "Equip"
				elseif (numberOfPetsEquipped + 1) > player:WaitForChild("Values"):WaitForChild("MaxPetsEquipped").Value then
					return "Cannot Equip"
				end
			end
		end
		
	end)
	sort(newTemplate)
end

wait(2)
for i, v in pairs(player.Pets:GetChildren()) do 
	_G.newTemplate(v.Name)
end

replicatedStorage:WaitForChild("EggRemoteEvents"):WaitForChild("addPetList").OnClientEvent:Connect(function(player, petName)
	_G.newTemplate(petName)
end)

but idk how to call it for the traded pets like if i trade pet 1 and pet 2 i need it to update the inventory


local function CompleteTrade(player: Player, target: Player)
	local playerPets = TradeSelected[player.UserId]
	local targetPets = TradeSelected[target.UserId]
      
	if playerPets then
		for _, petname in ipairs(playerPets) do
			local petInstance = player.Pets:FindFirstChild(playerPets)
			  petInstance.Parent = target.Pets
			  
			ReplicatedStorage:WaitForChild("EggRemoteEvents"):WaitForChild("addPetList"):FireClient(player,playerPets)
			  
		end
		TradeSelected[player.UserId] = nil
	end

	if targetPets then
		for _, petname in ipairs(targetPets) do
			local petInstance = target.Pets:FindFirstChild(petname)
			petInstance.Parent = player.Pets
			ReplicatedStorage:WaitForChild("EggRemoteEvents"):WaitForChild("addPetList"):FireClient(target,targetPets)
		end
		TradeSelected[target.UserId] = nil
	end

	TradeAccepted[player.UserId] = nil
	TradeRequests[player.UserId] = nil
	Trading[player.UserId] = nil

	TradeAccepted[target.UserId] = nil
	TradeRequests[target.UserId] = nil
	Trading[target.UserId] = nil

	Remotes.TradeCompleted:FireClient(player)
	Remotes.TradeCompleted:FireClient(target)
end

this is the eror
Argument 1 missing or nil - Client - PetInventory:56