Im trying to make a dropper like in a tycoon but i cant get it to delete the parts right. Once the limit is reached the ore never reaches the ground. What im trying to do is it'll delete ore that has already fell.
local dropper = script.Parent.Laser.Dropper local count = 0 local limit = 50 while true do wait(0.1) if count <= limit then count = count + 1 drop = script.Parent.Ore:Clone() drop.Position = dropper.Position + Vector3.new(-5,0,0) drop.Parent = dropper drop.Transparency = 0 drop.Anchored = false drop.CanCollide = true else count = count - 1 ore = dropper:FindFirstChild("Ore") ore:Destroy() end end
You could store the ores in a table, and then iterate through the table and destroy them using a for loop.
Let me know if this isn't what you're going for, so I can edit my answer :)
local dropper,count,limit = script.Parent.Laser.Dropper,0,50 local ores = {} --Table to store ores --Function to clear ores function clearOres() for _,v in next,ores do count = count - 1 v:Destroy() wait(.1) end end while wait(.1) do if count < limit then count = count + 1 drop = script.Parent.Ore:Clone() drop.Position = dropper.Position + Vector3.new(-5,0,0) drop.Transparency = 0 drop.Anchored = false drop.CanCollide = true drop.Parent = dropper ores[#ores+1] = drop --Add ore to the table else clearOres() --Call the clearing function end end