How to give color to objects with a certain material?

Hello there! I need to make sure that each object with a certain material is given a certain color.

How do I do this?

Here is my script :

for i,v in pairs(workspace:GetChildren()) do 
	if v.ClassName == "Part" then
		if v.Material == Enum.Material.SmoothPlastic then
			v.BrickColor = BrickColor.new("Really red")
		end
	end 
end 

If you had a table:

local colourMap = {
 SmoothPlastic= Brickcolor.new(what u want),
 OtherMaterialName = Brickcolor etc
}

then

you could do

v.BrickColor = colourMap[nameOfVsMaterial]

if its possible to send the material name through as a string
if i understand you correctly

yes i was being lazy heh

1 Like