Destroy() Doesn't work?

Hello everybody

  1. I want the copied car (newCar) to be destroyed when a certain button is clicked.

  2. The problem is that it doesn’t work :

local CarParams = game.ReplicatedStorage:WaitForChild("GetCarParams"):InvokeServer(script.Parent.Name)
local CarImage = script.Parent.CarImage
local ShowPurchaseFrame = script.Parent.Parent.Parent.Parent.ShowPurchaseFrame

script.Parent.CarName.Text = CarParams.Name
script.Parent.Cost.Text = CarParams.Cost

script.Parent.MouseButton1Down:Connect(function()
	ShowPurchaseFrame:Fire(CarParams.Name, CarParams.Cost, CarParams.Power, script.Parent.CarImage)
	script.Parent.Parent.Parent.Coupes.Visible = false
	local newCar = game.ReplicatedStorage.ShopCars.Agera:Clone()
	newCar.Parent = workspace
	script.Parent.Parent.Parent.Parent.PurchaseFrame.BackButton.MouseButton1Click:Connect(function()
		newCar:Destroy()
	end)
end)

image

  1. i’ve tried to delete the newCar but it doesn’t work

Can someone help me, Thanks !

use Debris Instead.

local Debris = game:GetService("Debris")
Debris:AddItem(YourInstance,1) -- first argument is The Instance,Second is the amount of time to wait
1 Like