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)
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
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