Frame not being destroyed

I’m making a trading system and I want it to be like when I click the button, the button destroys itself, However, this doesn’t work.

Script:

local clonedTemplate = tradeFrame.Player1.PetsFrame.SelectPets.Template:Clone()
				clonedTemplate.Parent = tradeFrame.Player1.PetsFrame.SelectPets
				clonedTemplate.Name = v.Name
				clonedTemplate.Visible = true
				clonedTemplate.PetName.Text = v.Name

				local Model3D = module3D:Attach3D(clonedTemplate:WaitForChild('Display'),petModel)
				Model3D:SetDepthMultiplier(1.2)
				Model3D.Camera.FieldOfView = 5
				Model3D.Visible = true

				runService.RenderStepped:Connect(function()
					Model3D:SetCFrame(CFrame.Angles(0,tick() % (math.pi * 2),0) * CFrame.Angles(math.rad(-10),0,0))
				end)

	clonedTemplate.TextButton.Activated:Connect(function()
	clonedTemplate:Destroy()-- doesn't work?
end)

Replace the clonedTemplate:Destroy() and the line before it with this:

clonedTemplate.TextButton.MouseButton1Click:Connect(function()
       clonedTemplate:Destroy()
end)

Still not working, as I think there is no difference, Activated and MouseButton1Click are practically the same thing

Are there any errors? If not check is you referenced everything correctly

try printing if it the mouse click function works otherwise maybe try adding a wait

clonedTemplate.TextButton.MouseButton1Click:Connect(function()
       wait()
       clonedTemplate:Destroy()
end)

I have absolutely no idea but adding a task.wait fixed it. Thank you`

2 Likes