Trying to change color of everything inside a model

I am trying to change the color of everything inside a model through a script. Here is my code however it does not work

local Walls = workspace.Level1Ex.Walls

for _, part in pairs (Walls:GetDescendants()) do 
		part.BrickColor = 'Crimson'
end


image of the model
image

try this script

local Walls = workspace.Level1Ex.Walls

for _, part in pairs (Walls:GetChildren()) do 
		if Part:IsA("Part") then
               part.BrickColor = BrickColor.new(Color3.fromRGB())
        end
end

How could I make it so a random color is shown?

you can use BrickColor.random()

local Walls = workspace.Level1Ex.Walls

for _, part in pairs (Walls:GetChildren()) do 
		if Part:IsA("Part") then
               part.BrickColor = BrickColor.random()
        end
end

But that makes every part a different color and not all the same

(in case anyone stumbles onto this later, this worked)

local Walls = workspace.Level1Ex.Walls
local r = math.random(1,255)
local g = math.random(1,255)
local b = math.random(1,255)

for _, part in pairs (Walls:GetChildren()) do 
	part.BrickColor = BrickColor.new(Color3.fromRGB(r,g,b))
end

Oh you wanted it that way. Your script isn’t the best way to do it. Instead try this

local Walls = workspace.Level1Ex.Walls
local Color = BrickColor.random()
for _, part in pairs (Walls:GetChildren()) do 
		if Part:IsA("Part") then
               Part.BrickColor = Color
        end
end
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.