Using an Enum number for ContextActionService

I would like to know if it possible to substitute the Enum.KeyCode.(_) in the 4th argument of ContextActionService:BindAction() with an Enum number, like 101 (for the letter E). Like so:

ContextActionService:BindAction("Interacting",newFunc,false,101)

My concern is that the game will not know how to interpret the number, whether as a UserInputType Enum or a KeyCode Enum.

1 Like

Enum’s actually have a Value that is their ID. You should be able to use them interchangeably.

Enum.KeyCode.101 would work in this instance then?

They would be used like:

Part.Material = 1568
So no, you just put its ID.

That doesn’t apply to my situation however. I know you can do that, but the way I have it throws up the error:
[ContextActionService:BindAction called with an invalid hotkey (should be either Enum.KeyCode, Enum.UserInputType or string)]

Try putting the ID as a string? :man_shrugging:

1 Like

I’m not aware of method that allows you specify the type of enum for context action service but you can always just a create a table for it:

local function GetNumberEnums(Enum)
  local Table  = {}
   for _,v in ipairs(Enum:GetEnumItems()) do
         Table[v.Value] = v 
     end
    return Table
end

local Keycodes = GetNumberEnums(Enum.KeyCode)