Trash
Trash is a class that allows you to destroy an instance after a certain amount of time.
If the instance is destroyed before the time is up, the Trash
object will automatically clear itself
In addition to instances, this class can be used to destroy any class object that has a Destroy
method.
Migrating from Debris:
Debris:AddItem(part, 8)
-> Trash.new(part, 8)
Timed class destruction:
local MyClass = require(class)
local myInstance = MyClass.new()
Trash.new(myInstance, 10) -- Destroy the instance after 10 seconds
Use case:
local function partExplosion()
for i = 1, 100 do
local part = Instance.new("Part")
part.Parent = Workspace
Trash.new(part, 10) -- Destroy the part after 10 seconds
part.Touched:Connect(function()
part:Destroy()
-- `Trash` will now automatically clear the Trash object
end)
end
end
Functions
empty
Trash.
empty
(
) →
(
)
Destroys all instances waiting to be destroyed.
removeFromTrash
Trash.
removeFromTrash
(
instance:
any
) →
(
)
Stops an instance from being destroyed.
new
Trash.
new
(
life:
number?
,
--
The amount of time (seconds) to wait before destroying the instance. Defaults to 60 seconds.
callback:
function?
--
A callback function to call when the instance is destroyed
) →
Trash
Creates a new Trash object
Destroy
Destroys a Trash object