for i,v in pairs(game.Workspace:GetChildren()) do if v.Name == "Part" then if v.Material == "Grass" then v.BrickColor = BrickColor.new("Quail grey") else print("Not Grass") end end end
That's my current code, but unfortunately, not all children of Workspace have a material property so it gives an error like "Material is not a valid member of Camera" or something like that and stops working. I also have models in it, and scripts, etc.
Instead of checking the name, check if v:IsA('BasePart'). This includes parts, wedge, truss, union, etc.
Also Material is an Enum not a string.
To scan literally every object in workspace, do a recursive function:
function scan(x) for _,v in pairs(x:GetChildren()) do if v:IsA('BasePart') then if v.Material == Enum.Material.Grass then v.BrickColor = BrickColor.new("Quail grey") else print("Not Grass") end end scan(v) end end scan(workspace)