Material Values

Hello, so I was messing around with basic Properties when I got stumped. To sum it up I searched up materials of ROBLOX and I found a list of Values corresponding to their Material but I cannot find any tutorials or code to use these Values. My script creates a random 9 digit code, splits it into 3, each 0 - 255, then uses that to randomise color. So i attempted this with Enum.Material but it just says 256 is not a valid member of “Enum.Material” for example. Anyone know if its Possible to use these Values in Scripts?

sounds like you want the Enum.Material value.

I don’t know how many there are and whether or not your item goes out of range, but you can do this:

local mat
for _, material: EnumItem in next, Enum.Material:GetEnumItems(), nil do
    if material.Value == generatedNumber then mat = material break end
end

mat = mat or "No material found."
1 Like

You virtually never need to use a Material’s value. If you want to randomise materials:

local possibleMaterials = Enum.Material:GetEnumItems()
local index = Random.new():NextInteger(1, #possibleMaterials)

local material = possibleMaterials[index]
print(`{material.Value} - {material.Name}`)

There are other Enums where the value has more practical use such as ContextActionPriority. Enums like this are primarily for carrying the value when passing it to something that expects a number. So all enums do have a value but there are cases where it’s not important or useful to know. Material is one of them.


FWIW: Luau has had generic iteration for a while now. You can cut out all the extra keywords.

for _, material: EnumItem in Enum.Material:GetEnumItems() do

Yep, I know. It’s just personal preference. Thanks, though.