I’m making a game where blocks rain down on you and then despawn after 5 seconds. How do I give the blocks a lifespan?
✓ ANSWER ACCEPTED
How do I make parts have a lifespan?
1 answer
✓ Accepted answer
From what I understand, do you want to make blocks spawn and wait a seconds then remove
If so, I have the solution and how you use it:
Wiki page: Roblox Wiki Page - Debris
You can use Debris.
Example:
game:GetService("Debris"):AddItem(script.Parent,3) -- Remove script.Parent in 3 seconds.
Or you can use delay:
delay(3, function()
script.Parent:Destroy()
end)
Or wait:
wait(3)
script.Parent:Destroy()
The debris in my opinion is the most efficient.
For you script you can use this:
local Part = script.Parent -- Find part to remove
local DelayTime = 5
game:GetService("Debris"):AddItem(Part,DelayTime)
OR
local Part = script.Parent -- Find part to remove
local DelayTime = 5
delay(DelayTime, function()
Part:Destroy()
end)
OR
local Part = script.Parent -- Find part to remove
local DelayTime = 5
wait(DelayTime)
Part:Destroy()
The best is the Debris.
Any errors? tell-me on comments.
Hope it helped!
This discussion is preserved as it was. New answers, comments, and votes are closed.

8 comments
You provided a duplicate example of each. Did you use this just to extend the answer?
I wanted to demonstrate several ways how to use
I completely understand, it is respectable that you put more of your time into the answer to give more examples to make it easier to understand the usability!
But it's obvious you can use variables. You used that only to extend the answer. They're exactly the same. It would be like me answering a question on how to print 7. I would just say print(7), not print(3 + 4) or whatever.
I used variables to make it easier for the person to understand and also to be completely editable.
but they can do it themselves
If he doesnt know how to destroy a block likely he doesnt have a good grasp on variables either. I think Hastee explained it perfectly.
Agree