Color all Parts within the Folder

local MainModel = script.Parent
local Walls = MainModel.MainWallPart

for i, v in pairs(Walls:GetChildren()) do
	
	if v then
		local randomColor = math.random(1, 5)
		
		if randomColor == 1 then
			v.BrickColor = BrickColor.new("Smoky grey")
		end
		if randomColor == 2 then
			v.BrickColor = BrickColor.new("Black")
		end
		if randomColor == 1 then
			v.BrickColor = BrickColor.new("Cocoa")
		end
		if randomColor == 1 then
			v.BrickColor = BrickColor.new("Slime green")
		end
		if randomColor == 1 then
			v.BrickColor = BrickColor.new("Dark taupe")
		end
	end
	
end

This is my script, and it works perfectly, but one thing I want to change is when the parts within the folder get colored, they all become different colors. I want the color of all the parts random, but uniform.

Any help is appreciated!
(hopefully that made sense)

1 Like

I would put all the colors you want in a table, and then using this to get a random color out of it:

table[math.random(1, #table)]

I cannot provide a 100% working example script right now, but I can later if you would like.

Edit:

local colors = {BrickColor.new("Red"), BrickColor.new("Blue"), BrickColor.new("Green")}

local randomColor = colors[math.random(1, #colors)]

Hope this helps,
Fizzitix

2 Likes

This makes my script a lot more clean, and it works the same, but it still makes every part a different color.

What I want is a randomizer, (like this), and then make all the parts the same RANDOM color.

Thanks for your help anyway!

1 Like

Like @Fizzitix said, you can use a table to randomize colors easily.

local MainModel = script.Parent
local Walls = MainModel.MainWallPart
local Colors = {"Smoky grey", "Black", "Cocoa", "Slime green", "Dark taupe"}

for i, v in pairs(Walls:GetChildren()) do
	if v then
		local Randomize = Colors[math.random(1, #Colors)]
		v.BrickColor = BrickColor.new(Randomize)
	end
end

Also if you want to get the same random color for every walls, you just have to put the randomize variable before the for_do.

local MainModel = script.Parent
local Walls = MainModel.MainWallPart
local Colors = {"Smoky grey", "Black", "Cocoa", "Slime green", "Dark taupe"}

local Randomize = Colors[math.random(1, #Colors)]

for i, v in pairs(Walls:GetChildren()) do
	if v then
		v.BrickColor = BrickColor.new(Randomize)
	end
end
2 Likes

You could still use it, but instead of randomizing a new color each time, just randomize it once and then apply that color to every single part.

1 Like

First do what @Fizzitix said because that will clean up your code alot.

to make everything uniform, you should pick out the color outside the loop, then color the bricksi n the loop

local MainModel = script.Parent
local Walls = MainModel.MainWallPart

local colors = {
BrickColor.new("Smoky grey"),
BrickColor.new("Black"),
BrickColor.new("Cocoa"),
BrickColor.new("Slime green"),
BrickColor.new("Dark taupe")
}

local randomColor = colors[math.random(1, #colors)]

for _,v in ipairs(Walls:GetChildren()) do
    v.BrickColor = randomColor
end
3 Likes

Oh yeah! This works exactly the way I wanted, thank you!

1 Like

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