an extension to Roblox Debris Service
- You can use this to:
- Disconnect RBXScriptConnections
- Destroy Instances
- Remove tables with a .Destroy method
- With Added functionality of:
- Adding multiple items at once
- Canceling Debris
- Overriding lifeTime
- Setting Debris.Destroyed callback
-- Structure
Debris2 = {
["Instances'] = {
[Debris: instance or table or RBXScriptConnection] = {
["lifeTime"] = lifeTime: number,
removalTime = tick() + lifeTime: number,
Destroyed = nil, -- Destroyed: callback Function | nil by default
Cancel = function -- remove references and disconnect Hearbeat
["Instance"] = item: (Instance or table or RBXScriptConnection),
},
},
}
-- Methods
- AddItem (item: Instance or table or RBXScriptConnection, lifeTime: number?) -> Debris
- AddItems (arrayOfItems: {Instance, table, RBXScriptConnection}, lifeTime: number?) -> void
- GetAllDebris () -> Debris2.Instances
- GetDebris (item: Instance or table or RBXScriptConnection) -> Debris2.Instances.Debris
-- Example Code
local Debris2 = require(game.ServerScriptService.Debris2)
local parts = {}
for i = 1, 5 do
local part = Instance.new("Part")
part.Name = i
part.Anchored = true
part.Parent = workspace
local debris = Debris2:AddItem(part,3)
function debris.Destroyed()
print("Destroyed",part)
end
if i == 1 then
debris.Cancel()
end
table.insert(parts,part)
end
Debris2:AddItem({},3).Destroyed = function()
print("DESTROYED")
end
Debris2:AddItem(parts[2].AncestryChanged:Connect(function(...) print(...) end),3).Cancel()
Debris2:AddItems(parts,4)
Debris2:getDebris(parts[1]).Cancel()
wait(5)
print(#Debris2:getAllDebris())
-- Motivation
As you already know Debris doesn’t have a lot of functionality, in-fact there’s only one method you can use :AddItem And it could be quite limiting
Debris2 = {
["Instances'] = {
[Debris: instance or table or RBXScriptConnection] = {
["lifeTime"] = lifeTime: number,
removalTime = tick() + lifeTime: number,
Destroyed = nil, -- Destroyed: callback Function | nil by default
Cancel = function -- remove references and disconnect Hearbeat
["Instance"] = item: (Instance or table or RBXScriptConnection),
},
},
}