Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

What is the debris service??? How do I use it???

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!

3 comments

0

debris?

0

There is a service called the debris service

0

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

1 answer

✓ Accepted 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

0

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

0

Ok

1

Lol, I thought I could use this for realistic destruction, but it’s just another way to destroy parts.

0

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

0

u really went all out with the formatting...

0

@usernamewitheld consistency/readability are important for understanding code

This discussion is preserved as it was. New answers, comments, and votes are closed.