Is there a script I can use in the command bar to delete something based on color?

Hello so I am woking on an aquarium showcase pretty cool yeah so I made a huge mistake by placing lines everywhere and they are all yellow is there a script that i can put in the command bar to delete them all?

1 Like

You can simply loop through the entirety of workspace:GetDescendants(), meaning everything parented under workspace even children of children, check if its BrickColor is the color you want, or check Color3 if you’re using that, and if so, :Destroy() it.

for i, v in pairs(worksapce:GetDescendants()) do --v is the current object
    if v.BrickColor == BrickColor.new("Bright yellow") then --check if the current object is colored "Bright yellow"
        v:Destroy() --destroy that object if so
    end
end

Writing such code in the command bar might be confusing since it’s all in one line.

3 Likes

it did not work

30charsssssssssssssssssssssssssssssssssssssss

You may be trying to index BrickColor on an Instance that isn’t a BasePart which will result in an error.

To fix this, use the IsA method to check it’s class:

for _, Child in pairs(worksapce:GetDescendants()) do
    if (Child:IsA("BasePart") and Child.BrickColor == BrickColor.new("Bright yellow")) then
        Child:Destroy();
    end
end
1 Like

i think it may be the issue is its not in pairs