Despawn parts after a little while

the title explains itself

how do I make a script that despawns a part after a little while?

2 Likes

just have this script inside the part:

wait(100) --This is 100 seconds for example. 
script.Parent:Destroy() --Destroys the part.
1 Like

Do you want the time to be a random time between times?

Like, a random number in between 30 and 40 seconds.

1 Like

yes, something like that 30charrrrrssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss

1 Like

Okay. Put this script inside of the part.

local number = math.random(30,40) -- Change "30,40" to numbers you want the random number to be selected within.

wait(number)
script.Parent:Destory()
1 Like

Sorry if my comment above is messed up. I am currently on low Reception lol

You should use Debris:AddItem() for this, not wait. The article should explain why.

game:GetService("Debris"):AddItem(script.Parent, math.random(30, 40))
3 Likes

Wow, you just introduced me to both the Debris service and the task.wait() function (which was in the article), dang those are both so useful! If only I learned that a few years ago.

1 Like