Is there a way to loop through all part materials?

I know that I could use Enum.Material:GetEnumItems(), however this also includes smooth terrain materials, and I only want regular part materials. Is there a way I can distinguish between them, or even better just only get the part mateirals?

3 Likes

I don’t think there is - and since a blacklisting method takes the same time to make, you might as well manually make an array of materials then just iterate through it.

local materials = {"Glass", "Wood", "etc."}

for i = 1, #materials do
    local materials = materials[i]
    print(Enum.Material[material])
end
1 Like

Alright, that’s what I’ve been doing, I just wanted to know if there was a better way.

Thanks for the help!

I tried a few hacky things, including ray casting and checking physics properties. I couldn’t find anything to check if a part material works.

Would it be possible to create an array using this method?

local materials = {}

function check(material)
	local part = Instance.new("Part")
	part.Material = material
	return true
end

for _,material in pairs(Enum.Material:GetEnumItems()) do
	local isPartMaterial, message = pcall(check, material) -- isPartMaterial is only true if it doesn't error
	
	if isPartMaterial then
		materials[#materials + 1] = material
	end
end

Edit: Nope, I just tested it.

1 Like

That is something else I checked. Doesn’t error.

There has to be SOME way to find it apart from making the array manually, right?

There isn’t even a pattern in the Value of the materials…

1 Like

{"Plastic","SmoothPlastic","Neon","Wood","WoodPlanks","Marble","Slate","Concrete","Granite","Brick","Pebble","Cobblestone","CorrodedMetal","DiamondPlate","Foil","Metal","Grass","Sand","Fabric","Ice"}

With as bonus the js to generate it from the wiki page;

var mats = [];
var table = document.getElementsByClassName("wikitable")[0];
for (var i = 1, row; row = table.rows[i]; i++) {
     var col = row.cells[1];
     var col2 = row.cells[8];
     mats.push(col.innerText);
     mats.push(col2.innerText);
}
var LuaArray = "{"
for(var i = 0; i < mats.length; i++){
LuaArray += '"' + mats[i] + '",';
}
LuaArray = String.substr(LuaArray,0,(LuaArray.length-1) );
LuaArray += "}";
console.log(LuaArray);

From: Documentation - Roblox Creator Hub

7 Likes

I was hoping there would be a way to get it in a script, but if this is the best way we have right now, then so be it. Thanks.

1 Like

The same could be done using HttpService if you parse the wiki page in-game, if that’s a better solution.

I just realized glass isn’t there since they don’t have a table entry for glass yet.

Ha, I reckon that’s a job for @Maximum_ADHD

1 Like

The main issue with this is that some materials are used for both parts and materials (e.g. Brick)

I know the solution was posted, however theres a new way to do it now.

for i,inner in pairs(Enum.Material:GetEnumItems()) do
print(i,inner);
end

This would be the new way to do it. Even though its 2 years I figured why not.

15 Likes