|
| 14 Oct 2015 09:47 PM |
Hey guys I thought it'd be cool to make a new series I call script of the day, basically some days I post a script and give you a few days to understand it before I post another but it might have days in a row if they're simple brick scripts or something.
Anyway here it is: game.Workspace.Player.Head:Remove()
A classic this script removes players head, change the name to use in your game. Depending on the responses I may wait a few days or not, comment below if you get it and request for scripts! |
|
|
| Report Abuse |
|
|
Lineout
|
  |
| Joined: 06 Nov 2012 |
| Total Posts: 684 |
|
|
| 14 Oct 2015 09:48 PM |
I have a feeling the form leaders are going to destroy you for this.
Eyyyo |
|
|
| Report Abuse |
|
|
lostend
|
  |
| Joined: 21 Aug 2011 |
| Total Posts: 8265 |
|
|
| 14 Oct 2015 09:50 PM |
my understanding of it:
a useless script that can error if player doesn't exist and uses a deprecated method to parent it to nil |
|
|
| Report Abuse |
|
|
Lineout
|
  |
| Joined: 06 Nov 2012 |
| Total Posts: 684 |
|
| |
|
|
| 14 Oct 2015 09:51 PM |
| lostend: Good point! That's called a static reference, which means you have to make sure Player exists. |
|
|
| Report Abuse |
|
|
|
| 14 Oct 2015 09:52 PM |
bruh
workspace.Player1.Head:Destroy()
please use Destroy lol. And no need for game.Workspace, you can just use workspace.
-The [Guy] |
|
|
| Report Abuse |
|
|
|
| 14 Oct 2015 09:53 PM |
| Both of your "corrections" are changes, but I will consider using those in the future! |
|
|
| Report Abuse |
|
|
| |
|
|
| 14 Oct 2015 09:55 PM |
:Destroy() > :Remove(), because the latter is deprecated.
-The [Guy] |
|
|
| Report Abuse |
|
|
Lineout
|
  |
| Joined: 06 Nov 2012 |
| Total Posts: 684 |
|
|
| 14 Oct 2015 09:55 PM |
Remove() being deprecated is not an opinion.
Eyyyo |
|
|
| Report Abuse |
|
|
|
| 14 Oct 2015 09:58 PM |
"Deprecation is an attribute applied to a computer software feature, characteristic, or practice to indicate that it should be avoided"
It's recommended but in some cases like this it's better. |
|
|
| Report Abuse |
|
|
|
| 14 Oct 2015 09:59 PM |
Better? Curious, how so? Being deprecated means you shouldn't rely on it because it may or may not exist in the future and if it doesn't, will break your scripts. It also usually means there is a newer alternative method that is superior in some way.
-The [Guy] |
|
|
| Report Abuse |
|
|
| |
|
|
| 14 Oct 2015 10:01 PM |
| It was made first its faster, if you need that additional functionality you use destroy. |
|
|
| Report Abuse |
|
|
|
| 14 Oct 2015 10:02 PM |
| I'm curious... If we used :Destroy() on 1000 objects, and used :Remove() on 1000 objects, which one would be faster or more efficient? |
|
|
| Report Abuse |
|
|
|
| 14 Oct 2015 10:04 PM |
Remove() exists for compatibility and should not be used in new scripts. It shouldn't.
:Destroy will disable it from being re-parented after being set to nil and it disconnects all functions that are acting on it. It calls the same function for all of its children. This "Additional functionality" is rather important.
-The [Guy] |
|
|
| Report Abuse |
|
|
|
| 14 Oct 2015 10:05 PM |
| I'm not interested in that aspect of the situation, I said which is more efficient? |
|
|
| Report Abuse |
|
|
|
| 14 Oct 2015 10:11 PM |
I don't know. Run a test and find out. Take the tick() at the end minus the tick() at the start for both functions. Compare the differences.
-The [Guy] |
|
|
| Report Abuse |
|
|
chimmmihc
|
  |
| Joined: 24 Jul 2014 |
| Total Posts: 2420 |
|
|
| 14 Oct 2015 10:26 PM |
Why not this? It's not the best thing in the world but it looks like your going for one liners.
local FoundCharacter = Player and Player.Character and Player.Character:FindFirstChild("Head") if FoundCharacter then Player.Character.Head:Destroy() else return end
Would that not be better? Is the point of this series fame or to teach because as of right now you might as well as thought of a name pasted a line of code and begged for attention. Either way you got the attention. |
|
|
| Report Abuse |
|
|
|
| 14 Oct 2015 10:26 PM |
They both vary from .1365s to .1428s The difference is negligible on average and neither has any sort of advantage for time. |
|
|
| Report Abuse |
|
|
chimmmihc
|
  |
| Joined: 24 Jul 2014 |
| Total Posts: 2420 |
|
|
| 14 Oct 2015 10:29 PM |
| Speed is not the problem with using remove(), the problem is remove doesn't completely delete the instance from the data model. However destroy disconnects the instance completely. I believe :) |
|
|
| Report Abuse |
|
|
|
| 14 Oct 2015 10:34 PM |
| I tried using both with 1000 pieces... I don't think it matters. |
|
|
| Report Abuse |
|
|
chimmmihc
|
  |
| Joined: 24 Jul 2014 |
| Total Posts: 2420 |
|
|
| 14 Oct 2015 10:42 PM |
| It does because when you remove instances they're still technically there, which can potentially use resource time. |
|
|
| Report Abuse |
|
|
| |
|
|
| 15 Oct 2015 12:53 AM |
getfenv()["remove"] = function(obj) game.Destroy(obj) end
remove(game.Workspace.Player.Head)
Save a whopping 1 char. Only really useful when you call remove 54 different times in your script. |
|
|
| Report Abuse |
|
|