Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How would i delete the oldest part?

Asked by 7 years ago

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

1 answer

Log in to vote
0
Answered by
Goulstem 8144 Badge of Merit Moderation Voter Administrator Community Moderator
7 years ago
Edited 7 years ago

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
0
This is close but im looking for something that deletes ores constantly instead of placing them all then removing. NinjaNickO 0 — 7y
Ad

Answer this question