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

how to delete a bunch of parts that are the same material?

Asked by 6 years ago

hello i want to delete all these parts that are all corroded material

2 answers

Log in to vote
0
Answered by 6 years ago

Try this!

function destroyPartsOfMaterial(child,material)

    for ind, part in pairs(child:GetChildren()) do
        if part:IsA("BasePart") and part.Material==Enum.Material[material] then
            part:Destroy()
        end
        destroyPartsOfMaterial(part,material)
    end

end


destroyPartsOfMaterial(workspace,"CorrodedMetal")

You can use this for any material! Just change CorrodedMetal to the material you want!

0
thank you sir mahaI_kita 0 — 6y
Ad
Log in to vote
0
Answered by 6 years ago

Here's a non-recursive solution:

local Material = "Neon"

for _,part in pairs(workspace:GetDescendants()) do
    if part:IsA("BasePart") and part.Material == Enum.Material[Material] then
        part:Destroy()
    end
end
0
If you call my function on Workspace, it'll do the exact same thing this does. GetDescendants() on workspace gets all the descendants of Workspace, which is the same thing my function does. optiplex123 21 — 6y

Answer this question