generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

Re: Is :Destroy() better than :Remove()?

Previous Thread :: Next Thread 
killjoy37 is not online. killjoy37
Joined: 27 Aug 2008
Total Posts: 2821
17 Dec 2011 06:15 PM
If so, why? What can each do differently than the other?
Report Abuse
mage11561 is not online. mage11561
Joined: 03 Sep 2008
Total Posts: 13217
17 Dec 2011 06:26 PM
Yes,
:Remove() just nils the Parent and its children.
:Destroy() completely gets rid of it.
Report Abuse
iamogggg is not online. iamogggg
Joined: 09 Sep 2008
Total Posts: 642
17 Dec 2011 06:31 PM
Depends on what you're trying to do. Generally, yes, unless you want to access the object after you get rid of it.

But if you wanted to do that, you could just use .Parent = nil
Report Abuse
killjoy37 is not online. killjoy37
Joined: 27 Aug 2008
Total Posts: 2821
17 Dec 2011 06:37 PM
Can you give an example of where i would want to access the object after i got rid of it?
Report Abuse
iamogggg is not online. iamogggg
Joined: 09 Sep 2008
Total Posts: 642
17 Dec 2011 06:41 PM
Very rarely. For example, I made something where it "rewinds" time, and the script has a table with a key of every object in the workspace. If someone pushed a block off of the edge of the map, and it got removed, I wanted to be able to fetch it, Parent it back into the workspace, and move it to its original position.
Report Abuse
killjoy37 is not online. killjoy37
Joined: 27 Aug 2008
Total Posts: 2821
17 Dec 2011 06:42 PM
Ok. I see. Thanks
Report Abuse
crazyman32 is not online. crazyman32
Joined: 13 Apr 2008
Total Posts: 18027
17 Dec 2011 06:44 PM
Remove just sets its parent and its descendants parents' to nil. Destroy does the same, however it locks the object too, which means you cannot set its parent anymore. Therefore its parent will remain nil forever now.
Report Abuse
iamogggg is not online. iamogggg
Joined: 09 Sep 2008
Total Posts: 642
17 Dec 2011 06:58 PM
Weelll.. no. It doesn't just do that. It actually DESTROYS the part. It's not in "nil," it just doesn't exist.
Report Abuse
Wil2 is not online. Wil2
Joined: 01 Feb 2008
Total Posts: 728
17 Dec 2011 07:01 PM
nil = nothing
if something is nil, it doesn't exist.
Report Abuse
swmaniac is not online. swmaniac
Joined: 28 Jun 2008
Total Posts: 15773
17 Dec 2011 07:23 PM
Ahem.

local p = Instance.new("Part")
p:Destroy()
print(p)
print(p.BrickColor)

>Part
>Medium stone grey

No, it sets the parent and then locks it.
Report Abuse
crazypotato4 is not online. crazypotato4
Joined: 22 Feb 2010
Total Posts: 20000
17 Dec 2011 07:25 PM
@swmaniac: Is that not exactly what Remove does? :l
Report Abuse
swmaniac is not online. swmaniac
Joined: 28 Jun 2008
Total Posts: 15773
17 Dec 2011 07:26 PM
The difference between :Destroy() and :Remove() is that after calling Destroy, the parent property is locked, attempting to set it gives an error.
Report Abuse
killjoy37 is not online. killjoy37
Joined: 27 Aug 2008
Total Posts: 2821
17 Dec 2011 09:59 PM
Which is quicker?
Report Abuse
cool12309 is not online. cool12309
Joined: 21 Sep 2008
Total Posts: 1442
17 Dec 2011 10:02 PM
I don't know, but just use what you plan to do.

If you plan to re-use it later, use :Remove()
If you don't, use :Destroy()

End.
Report Abuse
swmaniac is not online. swmaniac
Joined: 28 Jun 2008
Total Posts: 15773
17 Dec 2011 10:06 PM
@Cool

Uh, .Parent = nil should be used for what you called :Remove() cases. :Remove() should not be used at all anymore. To quote a mod:

"There are two things that could be considered removing,
Removing the object from the game temporarily so that physics aren't used on it; it can be placed back into the game later;
Deleting an object.

Remove did neither."
Report Abuse
Varp is not online. Varp
Joined: 18 Nov 2009
Total Posts: 5333
17 Dec 2011 10:48 PM
Use Obj:Destroy() if you want to destroy an object.
Use Obj.Parent = nil if you want it to go away, but not forever.

Don't use Obj:Remove() in new scripts because it is deprecated.
Report Abuse
SarahAngel is not online. SarahAngel
Joined: 12 Dec 2009
Total Posts: 2166
17 Dec 2011 11:52 PM
since when did :Destroy() come out? -.-
Report Abuse
JulienDethurens is not online. JulienDethurens
Joined: 11 Jun 2009
Total Posts: 11046
18 Dec 2011 12:03 AM
"Depends on what you're trying to do. Generally, yes, unless you want to access the object after you get rid of it."

You shouldn't use Remove on an object if you want to use it later. Even if it works, you're not supposed to.

In fact, you wouldn't be supposed to anyways since Remove is deprecated, but EVEN if it wasn't, you still wouldn't be supposed to.

"Remove just sets its parent and its descendants parents' to nil. Destroy does the same, however it locks the object too, which means you cannot set its parent anymore. Therefore its parent will remain nil forever now."

Destroy does more things than that. It also removes connections and does some other things.

"Weelll.. no. It doesn't just do that. It actually DESTROYS the part. It's not in "nil," it just doesn't exist."

Wrong. Using Destroy on a part doesn't deallocate it.

"No, it sets the parent and then locks it."

And removes connections, and destroys some of the functionalities of the object, and calls itself on all the children.

"Which is quicker?"

Destroy, by far.

"If you plan to re-use it later, use :Remove()"

Wrong. Wrong wrong wrong. If you want to use it later, you don't want to remove it, you just want to set its parent to nil temporarily. And anyways, Remove is deprecated, so you shouldn't use it.
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image