I heard someone talking abut debris service and I want to know what it is, what it does, and how I use it. Any helpful YT vids wold also be appreciated!
What is the debris service??? How do I use it???
1 answer
Debris is a service that can be used to remove instances without yielding the code.
For example;
local Debris = game:GetService("Debris")
local Part = Instance.new("Part")
Debris:AddItem(Part, 1)
So, in :AddItem it takes in 2 arguments. The instance you want to add, and the lifetime (or basically, the wait time) before it's actually added.
Once the timer has expired (in our example, after 1 second) the part is removed in the same manner is if doing Part:Destroy().
The reason this is useful is because, again, you won't have to yield your code by doing:
local Part = Instance.new("Part")
wait(1)
Part:Destroy()
Instead, we can run code after the Part is added without losing any time in the code.
local Debris = game:GetService("Debris")
local Part = Instance.new("Part")
Debris:AddItem(Part, 10)
--Do other stuff immediately even without waiting 10 seconds
print("Not yielded")
print("Still not yielded")
print("Etc, lul")
Hopefully, this helps! I definitely recommend using it.
6 comments
Also, definitely recommend using the wiki next time for stuff like this. You can get your answers much faster and more simply explained. Debris link: https://developer.roblox.com/en-us/api-reference/class/Debris
Ok
Lol, I thought I could use this for realistic destruction, but it’s just another way to destroy parts.
Heh, it be like that sometimes. I Also thought that was the case as well when i was newer. I thought "Debris" referred to like explosion instances and stuff LUL
u really went all out with the formatting...
@usernamewitheld consistency/readability are important for understanding code
This discussion is preserved as it was. New answers, comments, and votes are closed.

3 comments
debris?
There is a service called the debris service
The debris service allows you too schedule removal of the object without pausing your code you can find out how too use it here https://developer.roblox.com/en-us/api-reference/class/Debris