How do i get the Enum integer value from a material?

I want to Tween the material of an object. To do this, TweenService wants me to give it an integer value for the material (for example, SmoothPlastic’s Enum Value is 256)

The problem is, after i tween it to a material such as neon, i need it to return to its original Material. To do this, i store a variable prior to the tween (OldMaterial = i.Material) for use later when i tween it back. But it once again needs an integer value for the tween, so that means somehow i need to get an integer from the part’s material value. (So for example, if the material was SmoothPlastic, i would need a way to get 256 from that in order to tween it)

Does anyone have any ideas on how to do this? i cannot find any converters/constructors in the roblox Lua documentation.

2 Likes

Weird you would ever need to do this, but Enum’s have Name and Value properties.

EX: Enum.Material.SmoothPlastic.Value

9 Likes

Thank you. And to answer your question of why i would ever need to do this:

https://gyazo.com/0a4f4cc88a97608fe545158ae95b2b50

3 Likes

What about from the number to get the material?

In the future, especially if a post is 4 years old, you should still create a new request asking for personnel help in Help and Feedback > Scripting Support. I will still answer your question.

Enum.Material:GetEnumItems()[number]

example:

print(Enum.Material:GetEnumItems()[1] == Enum.Material.Plastic) --Prints true

1 Like