Debris Service doesn't work after the original script gets deleted!

The title here is poorly worded, (since I don’t really know how to explain it)

but when the script that summoned DebrisService onto a part gets deleted, DebrisService wont delete that part after a X amount of time.

local Part = instance.new("Part",workspace)
game:FindService("Debris"):AddItem(Part,10)
script:Destroy() --Destroying the script cancels DebrisService

This can be problematic, since i make gears for a living, DebrisService is one of my main Services to use, when a Player dies with a gear equipped, the script gets destroyed once a character gets unloaded, so a loose projectile for example can get lost, increasing Debris in the workspace.

Usually my way of fixing this, is to create a “Fake” DebrisService, using a separate ServerScript,
since the script still runs after the player has died.

 local part = Instance.new("Part", workspace)
part.BrickColor = BrickColor.Red()

game:FindService("Debris"):AddItem(part, 5)

script:Destroy()
print("woop")

--> woop

??

Huh, technically speaking Debris service can be called by find service but I’ve never seen findservice used in such a way. You can always get Debris service via game:GetService() and [I] preferably should be used that way.

Is there something I’m missing here, is there a reason to use findservice for this?
Try using GetService() if you haven’t already, if that doesn’t fix anything then this might be a bug.

I don’t think it has anything to do with :FindService, because i have been using :GetService for ages now, someone has told me that :FindService is a better alternative to :GetService.

If i was doing a serious script then i would do something like this:

local Debris = game:GetService("Debris") or game:FindService("Debris")
1 Like

Destroying the script causes it not to run any code below the part where it says “script:Destroy()” because your essentially deleting the script

Hmm all things considered this seems like a bug then.

Expectation of debris “Service should execute what it was told to do, even if the script that told it to do something no longer exists. Furthermore nothing is documented on the developer hub that the debris service won’t work if the calling script is destroyed.”

Well, Debris is an entire service, so it would be expected to delete something after the calling script gets destroyed, because essentially its the same thing as using:

delay(10, function()
     Part:Destroy()
end)

Do you think it needs a delay before the script gets destroyed like “wait()”?

1 Like

Adding a wait would certainly help get around the issue you are having.
If a normal wait doesn’t work try wait with the inputed time for debris service

It seems to work now, I guess I needed to add a wait(1/1000) to make it happen!

i think using:

game:GetService("Debris"):AddItem()

Like this causes slowness, since using variables like local Debris = game:GetService("Debris")
seems to make it “faster”

Don’t know who told you this but GetService should be used in almost all cases because it creates the service if it hasn’t loaded yet rather than returning nil which FindService will do

1 Like