Ive been trying to make a dropper that the blocks expire after awhile
function fire() local p = Instance.new("Part") p.Position = script.Parent.Position p.Size = Vector3.new(1,1,1) p.BrickColor = BrickColor.new(26) p.BottomSurface = 0 p.TopSurface = 0 p.Name = "TycoonBrick" p.Parent = script.Parent end while true do wait(2) fire() end
When creating the dropped blocks, add them to Debris to be deleted after a set amount of time.
function fire() local p = Instance.new("Part") p.Position = script.Parent.Position p.Size = Vector3.new(1,1,1) p.BrickColor = BrickColor.new(26) p.BottomSurface = 0 p.TopSurface = 0 p.Name = "TycoonBrick" p.Parent = script.Parent game:GetService("Debris"):AddItem(p,5) -- will delete after 5 seconds end while true do wait(2) fire() end
You should try using the wait()
function to wait until we want to remove the part (like you did with the cooldown) and then use Destroy()
to get rid of the part.
Try this:
function fire() local p = Instance.new("Part") p.Position = script.Parent.Position p.Size = Vector3.new(1,1,1) p.BrickColor = BrickColor.new(26) p.BottomSurface = 0 p.TopSurface = 0 p.Name = "TycoonBrick" p.Parent = script.Parent wait(5) --replace 5 with the wait time p:Destroy() --call Destroy() end while true do wait(2) fire() end
Alternatively, you can try to use the Debris
method like mattscy did.
function fire() local p = Instance.new("Part") p.Position = script.Parent.Position p.Size = Vector3.new(1,1,1) p.BrickColor = BrickColor.new(26) p.BottomSurface = 0 p.TopSurface = 0 p.Name = "TycoonBrick" p.Parent = script.Parent game:GetService("Debris"):AddItem(p,5) --replace 5 with wait time end while true do wait(2) fire() end
Also, I suggest you to read the article about Debris