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?
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!