Check if variable is Enum?

Hello fellow developers, As the title says, I wan’t to check if variable is Enum or not, so is there a way to do this?

You’ll want typeof.

print(typeof(SomeEnumItem)) --> EnumItem

typeof() is compatible with the various userdata (custom) value/instance types.

It’s already been mentioned. Just check if the typeof() of the value is equal to the typeof() of any EnumItem.

local var = Enum.KeyCode.A;
if typeof(var) == typeof(Enum.KeyCode.C) then -- // Comapre it to any existing EnumItem.
   -- // Whatever.
end;

I need if Enum variable is ANY enum.

local variable = Enum.AccessoryType.Face --random enum
local isEnum = (typeof(variable) == "EnumItem")
print(isEnum) --true
1 Like

It does work for that. I just picked a random EnumItem to get it’s type.

Why are you not trying something like; if enumcode == TheRealEnum