Randomized between given values doesn't work?

This script gives me the color “Medium stone grey” (sometimes), but this color isn’t in the given allColors! I guess this is a bug.

allColors = {
	"Shamrock",
	"Burlap",
	"Dark green",
	"Pine cone",
	"Moss",
	"Carnation pink"
}

script.Parent.Changed:Connect(function()
	local randomColor = allColors[math.random(1, #allColors)]
	for _, child in ipairs(script.Parent:WaitForChild("Color"):GetChildren()) do
		if child:IsA("Part")then
			child.BrickColor = BrickColor.new(randomColor)
		end
	end
end)

I believe its giving you Medium stone grey as a default, because the argument you provided to BrickColor.new() is not a valid brick color.

I am guessing those values in your table are actually being interpreted as keys.

Maybe try it like this:

allColors = {
	[1] = "Shamrock",
	[2] = "Burlap",
	[3] = "Dark green",
	[4] = "Pine cone",
	[5] = "Moss",
	[6] = "Carnation pink"
}
1 Like

I just tried it, but there’s still a chance for “Medium stone grey”. This doesn’t work :\

[4] = “Pine cone”

Needs a capital C for Cone. If it chose this option it would set default color as Pine cone doesn’t exist

1 Like