Should I use one over the other depending on the situation or does it not matter? Thanks.
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.
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 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.
Destroy: http://wiki.roblox.com/index.php?title=API:Class/Instance/Destroy Remove: http://wiki.roblox.com/index.php?title=API:Class/Instance/Remove
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!
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!
All I know is that, both works the same.