Assigning a color to each model?

Hey there.

I was wondering if there was a way to assign colors to models?

What I mean is:

House 1 has a color of only blue
House 2 has a color of only red

The colors get mixed now.

I have some code, but not much.

for i,v in pairs(Workspace.Map.Houses:GetChildren()) do
	
	local ColorLibrary = {  
		{Name = 'Red', Color = Color3.fromRGB(255, 0, 0)},
		{Name = 'Blue', Color = Color3.fromRGB(0, 243, 255)},
		{Name = 'Yellow', Color = Color3.fromRGB(230, 255, 0)},
		{Name = 'Purple', Color = Color3.fromRGB(59, 0, 255)}
	}
	
	if v.Name == "ColorPart" then
		local RandomColour = ColorLibrary[math.random(1, #ColorLibrary)]
		v.Color = RandomColour.Color
	end
	
end

Thanks!

Can you provide a screenshot of your houses model under workspace?

Are there any errors? I believe the issue is that the houses are models and models do not have a color property

get you my friend here the fix

for i,v in pairs(Workspace.Map.Houses:GetChildren()) do
	
	local ColorLibrary = {  
		{Name = 'Red', Color = Color3.fromRGB(255, 0, 0)},
		{Name = 'Blue', Color = Color3.fromRGB(0, 243, 255)},
		{Name = 'Yellow', Color = Color3.fromRGB(230, 255, 0)},
		{Name = 'Purple', Color = Color3.fromRGB(59, 0, 255)}
	}
	local random = math.random(1, #ColorLibrary)
	if v.Name == "ColorPart" then
		local RandomColour = ColorLibrary[random]
		v.Color = RandomColour.Color
	end
	
end
2 Likes