Enum value is way higher than GetEnumItems?

Hello,

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
image

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]
end

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

image

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
end
1 Like

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