Enum value is way higher than GetEnumItems?


I’m creating a script to serialize/de-serialize models, and lastly wanted to include materials. When trying to do this, my models Material.Value came out really high (> 1000), and when I tried to convert this back to an Enum using GetEnumItems(), I get this issue:

Table is GetEnumItems() and the number is the Material.Value

This results in the material being nil

function getEnum(value, enum)
    print(enum:GetEnumItems(), value)

    -- Adding 1 because .Value ranges from 0-x whereas the table goes from 1-x
    return enum:GetEnumItems()[value + 1]

The enum list ends at rubber being 45, but for some reason, “Grass” on the tree is 1296?


The above function works perfectly for the parts shape, but on not material. If anyone knows how to fix this, that would be really appreciated!

1 Like

:GetEnumItems() just returns all the items regardless of their value. If you look at Material | Documentation - Roblox Creator Hub, you can see that (for some reason) the values are extremely high. To fix this you can re-create the table returned from :GetEnumItems() by assigning the index of each enum item to their value.

local fixedTable = {};
for _,item in enum:GetEnumItems() do
    fixedTable[item.Value] = item
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.