I want to convert a string to enum
“Enum.KeyCode.X” (string)
to
Enum.KeyCode.X
I want to convert a string to enum
“Enum.KeyCode.X” (string)
to
Enum.KeyCode.X
Simply use the built-in tostring() function to achieve that.
Example:
local str = tostring(Enum.KeyCode.X);
print(typeof(str)); --string
Misread
You can use some string manipulation to attain that:
local code = str:reverse():split(".")[1]:reverse();
return Enum.KeyCode[code];
This is way easier if you just use string patterns
Enum.KeyCode[str:match('[^.]*$')]
"Enum.KeyCode"..Enum.KeyCode.X.Name
Never mind, this is for string to enum not enum to string.