Invalid argument #3 (Color3 expected, got number)


local colortable = {
 Color3.fromRGB(218, 133, 65),
Color3.fromRGB(163, 75, 75),
Color3.fromRGB(160, 132, 79),
 Color3.fromRGB(106, 57, 9),
Color3.fromRGB(255, 204, 153),
Color3.fromRGB(188, 155, 93),
Color3.fromRGB(196, 40, 28)
}

for i,v in pairs(workspace:GetDescendants()) do
    if v:IsA("BasePart") and v.Name == 'Leaves' then
        v.Color = math.random(1, #colortable)
    end
end

The title explains my error, Im trying to color some trees but its erroring

this is what causing the error since math.random only returns number and you would still have to index it, you would have to do

v.Color = colortable[math.random(1, #colortable)]
1 Like
for i, v in pairs(workspace:GetDescendants()) do
	if v:IsA("BasePart") and v.Name == 'Leaves' then
		v.Color = Color3.fromRGB(math.random(0, 255), math.random(0, 255), math.random(0, 255))
	end
end

This would provide truly random colors, if that was what you were trying to achieve.