How to make parts disappear after some time

Hey! I’m pretty new to scripting, and I found this simple script for my build, but I want the parts to disappear after some time, everything I tried makes it so the part spawns 5 seconds after the other, but I want them to spawn continuously, and after some time they’ll disappear. Thanks!
Here’s the script:

local shapes = {
Enum.PartType.Ball,
Enum.PartType.Cylinder,
Enum.PartType.CornerWedge,
Enum.PartType.Block,
Enum.PartType.Wedge,
}

while wait() do

local thing = Instance.new("Part",game.Workspace)
thing.Position = script.Parent.Position
thing.BrickColor = BrickColor.random()
thing.Shape = shapes[math.random(1,#shapes)]
thing.Size = Vector3.new(1,1,1)

end

1 Like

To make something disappear after some time, you can use Debris

1 Like

To put it simple

local Debris = game:GetService("Debris")
Debris:AddItem(Item, Time) -- Simple way

this will simply make it pop out of existence after the amount of time you give it. fair warning it requires seconds.

2 Likes