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!
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.