I've created I script which was intended to change the color of a car randomly every time the server was loaded, It worked... sorta. Instead of it changing the parts on a car to a solid color, I got a mixture of the two colors I allowed in my script, Yellow and White. Some of the car is Yellow and some White. I'm assuming it's because It's rolling the random function each time a child with a name "part" is found.
local sportscar2color = game.workspace.Cars.Sportscar2:GetChildren()
paintRandom = nil
function PaintCar(part)
paintRandom = math.random(1,2)
if paintRandom == 1 then
part.BrickColor = BrickColor.White()
elseif paintRandom == 2 then
part.BrickColor = BrickColor.Yellow()
end
end
for _, child in ipairs(sportscar2color) do
if child.Name == "Part" then
PaintCar(child)
end
end
How can I get my car to spawn and change all parts to the same randomly picked color?

5 comments
Alternatively, you could just change line 4 to "local paintRandom = math.random(1,2)", and remove line 7.
That is very clever either way, Thanks for the help. I am new to this but I have a general understanding.
That did it, I even added another car to it, although I had to add a wait of 0.1 because it didnt paint the cars anymore.
You can also use a BrickColorValue
Glad I could help :)