Help with colors

I have a script that spawns objects, and I want them to be a different random color each time, but they all spawn as the same color. Here is the script:

local colors = {
	BrickColor.new("Parsley green"),
	BrickColor.new("Deep orange"),
	BrickColor.new("Bright yellow"),
	BrickColor.new("Neon orange"),
	BrickColor.new("CGA brown"),
	BrickColor.new("Mulberry"),
	BrickColor.new("Sand green"),
	BrickColor.new("Quill grey"),
	BrickColor.new("Carnation pink"),
	BrickColor.new("Bright orange"),
	BrickColor.new("Dusty Rose"),
	BrickColor.new("Cork")
}

while true do
	local selectedSpillPoint = spillPoints[math.random(1,#spillPoints)]
	local newSpillCFrame = selectedSpillPoint.CFrame
	local spill = spillModel:Clone()
	local spillOrientation = spill.Orientation
	
	spill.Parent = game.Workspace
	spill.CFrame = newSpillCFrame
	spill.Orientation = spillOrientation
	spill.BrickColor = colors[math.random(1,#colors)]
	print("Spill made")
	task.wait(10)
end

How do I fix this?

Doesn’t BrickColor.Random() exist?

1 Like

I want it to be a random color from those in the table.

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

– this variable can choose for you a random color from your table.

That’s what I did. It’s not working.

Well, then the issue must be before that line, mind sending whole code?

try this:

spill.BrickColor = BrickColor.New(tostring(colors[math.random(1,#colors)]))

It’s already a BrickColor so that’s redundant.

Can you recolor the spill manually? If not, are you using meshes or Unions?

If it’s a union you don’t have ‘UsePartColor’ set.

It must not be a normal part as others have said. I just tested your code, and it worked perfectly fine.

Try doing

local colors = {
    [1] = Brickcolor.new('Parsley green')
    … and so on
}

It’s a union. How could I color all the parts of the union?

There should be a setting called UsePartColor in the properties window. Select your union and turn that on.

1 Like

Make function like

function PickColor(object)
 local pickedColor = colors[math.random(1,#colors)]
object.BrickColor = pickedColor
end

while true do
	local selectedSpillPoint = spillPoints[math.random(1,#spillPoints)]
	local newSpillCFrame = selectedSpillPoint.CFrame
	local spill = spillModel:Clone()
	local spillOrientation = spill.Orientation
	
	spill.Parent = game.Workspace
	spill.CFrame = newSpillCFrame
	spill.Orientation = spillOrientation
	PickColor(spill)
	print("Spill made")
	task.wait(10)
end