:Destroy doesn't destroy object but removes it's parent?

so, i have this short thing here:

if button.Selected == false then
														
    button.Selected = true
														
    print(v ,v.Parent)
    v:Destroy()
    print(v ,v.Parent)

end

v is an accessory thats put on the player, but anyway i tried this and noticed that it didn’t destroy it, it’s still there on the character
image

and so i looked in the output and saw this:
image
the object still exists so destroy just didn’t work, but now it doesn’t have a parent?

i didn’t know not having a parent was even possible, but its also still there in the character so it has a parent?

im confused so if anyone knows would be great

3 Likes

That’s what Destroy() mainly does, parenting the object to nil, with the exception of preventing memory leaks and locking it’s parent property, not allowing it to be brought back as well. You still have a reference to the accessory so it still exists, just not in the game.

2 Likes

so how would i go about actually destorying it, because its still there somehow physically?

1 Like

Using Destroy() just doesn’t allow you to change it anymore, and effectively removes it. You don’t need to worry about it still staying after that, if you do just set the reference to nil, in this case v = nil

1 Like

it seems like its getting destroyed on the server because it says the parent is nil the output, but on the client i can clearly see that the accessory is still on the character and it is still parented to it

this is a server script so i tried using a remote event, i sent v as a parameter and that works i checked with a print, but on the client the destroy doesnt even do anything, doesnt unparent or nothing

1 Like

You can just use getnilinstances() to see all nil Instances or Instances parented to nil.

If you do want to bring it back, you can just set the Parent property itself to nil, and set it back later to whatever Instance.

i dont need to set it back really i just need to destroy it

i tried parenting it to places like workspace instead of using :Destroy(), and the output says that the parent is workspace, but in the client the accessory is still there on the character and still parented to the character

this is inside a viewportframe and a worldmodel if you didnt see on the screenshot, could be something with that?

Try setting the Parent property to nil instead of using :Destroy(). Pretty unreliable alternative, but just try it.

same thing, parent is nil but still there on the client
image
image

1 Like

Try deleting it on the client?

tried it and it just doesnt work? i checked with a print it knows what v is but when i try to destroy it just does nothing, no errors or anything

Is something protecting the Instance from being destroyed? Running :Destroy() will destroy it under any circumstances, period.

where is v defined?

If you try setting

v = nil

after destroying it, that should remove the reference to the part.

ok so this is weird

so i used this:

print(v ,v.Parent)
v:Destroy()
v = nil
print(v ,v.Parent)

and this actually works, it removed the accessory from the character, however i got this error:


now this is pretty obvious, its just the second print not knowing what v is because i set it to nil

so i removed the print:

print(v ,v.Parent)
v:Destroy()
v = nil

and with the print removed it doesnt work anymore, no errors or anything, its just the first print and then nothing in the output

So you mean the accessory doesn’t get destroyed?

Try:

print(v ,v.Parent)
v:Destroy()
task.wait()
v = nil

alright well,

turns out there was something that caused it to clone twice, so it got destroyed and cloned again without me even noticing so, sorry

I asked you before if any script relating to the Instance is doing anything, because running :Destroy() will destroy it.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.