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

Changing color + material script?

Asked by
Hasburo 150
8 years ago
p = workspace:GetChildren() 
for i=1, #p do 
if p[i].className == "Part" or "Wedge" then
if p[i].BrickColor == BrickColor.new("White") and p[i].Material == "Slate" then
p[i].BrickColor = BrickColor.new("Grime")
p[i].Material = "Grass"
        end
    end
end

The problem I'm running into is that there are models in the workspace, and BrickColor & Material are not characteristics of Models.

So if you don't understand, I need this script to change any part or wedge that is colored white, and has the material called Slate.. except it also attempts to change the models in the workspace.

0
Your error was or "wedge", you needed to put p[i].className == "Wedge" although :IsA("BasePart") is a better alternative. DevSean 270 — 8y

1 answer

Log in to vote
0
Answered by
Kryddan 261 Moderation Voter
8 years ago
for _,v in pairs (workspace:GetChildren())
    if v:IsA("BasePart") then
        if v.BrickColor == BrickColor.new("White") and v.Material == "Slate" then
            v.BrickColor = BrickColor.new("Grime")
            v.Material = "Grass"
        end
    end
end

"Your error was or "wedge", you needed to put p[i].className == "Wedge" although :IsA("BasePart") is a better alternative." -DevSean

And I changed the for loop to a generic one just because I prefer it over numeric when working with objects.

0
Don't just past code, explain what was wrong and why your code works. DevSean 270 — 8y
0
didn't have time to do that at the time. Kryddan 261 — 8y
Ad

Answer this question