Cannot destroy cloned object

Hi. I want to destroy something while Changed event is triggered, by this code:

Instance.Changed:Connect(function()
	if Instance.Property ~= nil then
		script.ObjectToClone:Clone().Parent = plr.PlayerGui --does not matter where you wanna clone
		print("yes!")
	else
		script.ObjectToClone:Clone():Destroy()
		print("no!")
	end
end)

But the cloned object is not destroyed while the property of object is changed to nil. I know that the solution is adding the variables, but how to fix this without any variable?

1 Like

if i understood that correctly you need to remember this created clone
to destroy it instead of new clone you create here

I understand. I decided to use plr.PlayerGuiWaitForChild(“ObjectToClone”):Destroy() and it works!

1 Like

Im pretty sure its impossible without using variables as invoking :Clone() will create a separate clone

2 Likes

you can use collectionservice and remove them all that way

1 Like