Removing Objects After a Time
Removing Objects After a Time
Problem
You want to remove an object after a certain amount of time without interrupting a script’s execution.
Solution
Use the Debris/AddItem|AddItem()
method of Debris
.
game:GetService("Debris"):AddItem(game.Workspace.Part, 5)
Discussion
The Debris
service is used to make objects automatically clean themselves up after a certain amount of time. You can add an object to the cleanup list by using Debris/AddItem|AddItem()
and, as the second argument, specify the amount of time before the object is cleaned up (in seconds).