Help with Trading System

I am making a trading system, and currently I want it to be like when a player clicks on a pet to add it to the trade, the template that the player clicks on gets destroyed and a new template gets cloned on a different frame. Everything is working fine except that the template doesn’t get destroyed.

Script:

clonedTemplate.TextButton.Activated:Connect(function()
					local name = clonedTemplate.Name
					local result = remotes:WaitForChild('AddTradeItem'):InvokeServer(clonedTemplate.Name, 'Player1')
					
					if result == true then
						print(result) -- this is working it prints true
						clonedTemplate:Destroy()
						tradeFrame.Player1.PetsFrame.SelectPets.Visible = false
						local petTemplate = tradeFrame.Player1.PetsFrame.PetTemplates.Template:Clone()
						petTemplate.Parent = tradeFrame.Player1.PetsFrame.PetTemplates
						petTemplate.Name = name
						petTemplate.PetName.Text = name
						petTemplate.Visible = true
						
						petTemplate.TextButton.Activated:Connect(function()
							local addedTemp = tradeFrame.Player1.PetsFrame.SelectPets.Template:Clone()
							addedTemp.Name = petTemplate.Name
							addedTemp.Parent = tradeFrame.Player1.PetsFrame.SelectPets
							addedTemp.Visible = true
							addedTemp.PetName.Text = petTemplate.Name
							petTemplate:Destroy()
						end)
					end
				end)