Which one is more efficient, and in what situations should I use each?
What is the difference between Debris:AddItem and Destroy()?
2 answers
Well, there is 2 ways, of destroying a brick
example: you want to destroy a brick inside workspace, the most easiest way is you can call the function :Destroy(), but for example, if you want a script that runs anyway without having to wait, then you can use :AddItem(), because its accept 2 arguments, example
game:GetService("Debris"):AddItem(game.Workspace.Part,3), then the script will not yield but continues with the next code, so it does not yield for the part disappearing, but in the way we have :Destroy() and if you do like this
print("Deleting part in workspace, and waiting 3 seconds")
wait(3)
game.Workspace.Part:Destroy()
print("Part was destroyed, but the code was not executed here, it waited for 3 seconds")
additem:
print("Deleting part in workspace and waiting 3 seconds to delete it")
game:GetService("Debris"):AddItem(game.Workspace.Part,3)
print("This code was executed, but the part still have to wait 3 seconds before it gets deleted")
hope i helped
The AddItem should be used if you want a part to gets deleted but the code should still run to next step
Destroy has no delay argument and if you want a script to wait until it is destroyed, then use like
print("Waiting 3 seconds and then destroying the brick")
wait(3)
game.Workspace.Part:Destroy()
print([[This code needed to wait, but this line got executed after the "wait" line]])
AddItem adds items. Destory() well... Destroys.. Use which one is most helpful.
This discussion is preserved as it was. New answers, comments, and votes are closed.
