Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

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

Asked by 5 years ago

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!

0
debris? Luka_Gaming07 534 — 5y
0
There is a service called the debris service NickIsANuke 217 — 5y
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 tball124 0 — 5y

1 answer

Log in to vote
1
Answered by
Psudar 882 Moderation Voter
5 years ago
Edited 5 years ago

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.

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 Psudar 882 — 5y
0
Ok NickIsANuke 217 — 5y
1
Lol, I thought I could use this for realistic destruction, but it’s just another way to destroy parts. NickIsANuke 217 — 5y
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 Psudar 882 — 5y
View all comments (2 more)
0
u really went all out with the formatting... EmbeddedHorror 299 — 5y
0
@usernamewitheld consistency/readability are important for understanding code Psudar 882 — 5y
Ad

Answer this question