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
9 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 — 9y

4 answers

Log in to vote
3
Answered by 9 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:

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

and

s  = Instance.new("Part",workspace)
s: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:

s  = Instance.new("Part",workspace)
s:Remove()
s.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:

s  = Instance.new("Part",workspace)
s: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:

s  = Instance.new("Part",workspace)
s:Destroy()
s.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 — 9y
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 — 9y
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 — 9y
0
Also, which text are you talking about? DigitalVeer 1473 — 9y
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 — 9y
1
Ah, what you do is, type in a word, like 'Title' or something, then hit Enter, and then put, '-----' : basically 5 "-" DigitalVeer 1473 — 9y
0
Why didn't the Owner import that before?? woodengop 1134 — 9y
Ad
Log in to vote
1
Answered by 9 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.

local part = workspace.Part

part:remove()
wait(3)
part.Parent = workspace --The part will disappear for 3 seconds then come back.

This is the same as doing this

local part = workspace.Part

part.Parent = nil --Parent is nil, remove changes the parent of an object to nil
wait(3)
part.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.

local part = workspace.Part

part:Destroy()
wait(3)
part.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 9 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 9 years ago

All I know is that, both works the same.

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

Answer this question