Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
3

What is the difference between m:Destroy() and m:Remove()?

Asked by
AmVolt 60
10 years ago

Should I use one over the other depending on the situation or does it not matter? Thanks.

0
Ohh ok sorry I didn't realize you can do that. My bad. AmVolt 60 — 10y

4 answers

Log in to vote
3
Answered by 10 years ago

This is a common question many users have when scripting.

Remove is deprecated [meaning it's highly discouraged from use], while Destroy is the better method to use to get rid of an object.

Remove

Let's look at two scripts:

1= Instance.new("Part",workspace)
2s.Parent = nil

and

1= Instance.new("Part",workspace)
2s:Remove()

What you just saw above does the EXACT same thing. Remove merely sets the parent of the object to nil.

To prove this, we can do this:

1= Instance.new("Part",workspace)
2s:Remove()
3s.Parent = workspace

In the code example above, the part, although removed, is able to make its way to Workspace since all we did was just re-declare the parent and it came back.


Destroy

Destroy is different in a way:

1= Instance.new("Part",workspace)
2s:Destroy()

Sets the Parent property to nil, locks the Parent property, disconnects all connections and calls Destroy() on all children, thus why Roblox suggests we use Destroy over Remove

Let's prove this:

1= Instance.new("Part",workspace)
2s:Destroy()
3s.Parent = workspace

With the following code above, the part will never return.


Links

Destroy: http://wiki.roblox.com/index.php?title=API:Class/Instance/Destroy Remove: http://wiki.roblox.com/index.php?title=API:Class/Instance/Remove

0
We said the exact same thing... BTW how do you make the text so big? EzraNehemiah_TF2 3552 — 10y
0
Okay, you just edited your too look EXACTLY like mine... WTF? Did you just add links and big text to look professional so you get upvoted? Just make your answer less like mine... EzraNehemiah_TF2 3552 — 10y
0
First off, I always post a general outline of what the answer should be. Then I take the time to edit the post to add more information. I didn't even see your post till I finished editing. I didn't copy you at all. We just both know what we're talking about. DigitalVeer 1473 — 10y
0
Also, which text are you talking about? DigitalVeer 1473 — 10y
View all comments (3 more)
0
Well then okay, also I'm talking about the text like "Links" and "Destroy", they look like titles. EzraNehemiah_TF2 3552 — 10y
1
Ah, what you do is, type in a word, like 'Title' or something, then hit Enter, and then put, '-----' : basically 5 "-" DigitalVeer 1473 — 10y
0
Why didn't the Owner import that before?? woodengop 1134 — 10y
Ad
Log in to vote
1
Answered by 10 years ago

Remove is deprecated the other one isn't.

Remove only changes the parent to nil. So remove doesn't actually remove the object. So you can do this.

1local part = workspace.Part
2 
3part:remove()
4wait(3)
5part.Parent = workspace --The part will disappear for 3 seconds then come back.

This is the same as doing this

1local part = workspace.Part
2 
3part.Parent = nil --Parent is nil, remove changes the parent of an object to nil
4wait(3)
5part.Parent = workspace --The part will disappear for 3 seconds then come back.

Destroy actually destroys the object. If it's destroyed, it's done. You cannot bring it back.

1local part = workspace.Part
2 
3part:Destroy()
4wait(3)
5part.Parent = workspace --The part will disappear forever! and the script will also error since part does not exist anymore.


Hope this helps!

Log in to vote
1
Answered by 10 years ago

The different between Destroy and Remove is that;

Destroy: Destroy removes the Child/Target, then will lock the Child and it's Descendants, preventing it from being used again.

Remove: Remove only reverts the Child's Parent property to nil, without locking it or it's Descendants, allowing the user to use the Model/Child again, however, due to you being able to set a Child's Parent manually without remove [Is what I'm guessing], Remove has become Deprecated.

Hope this helped!

Log in to vote
-5
Answered by 10 years ago

All I know is that, both works the same.

1
No they do not... EzraNehemiah_TF2 3552 — 10y

Answer this question