Argument 1 missing or nil in keycode script

I’m new on InputObject, i want to make a script which contain some gamepad and keyboard functions, the problem is that i’m getting an error which i don’t know how to solve:

   
    local navGamepads = UserInputService:GetNavigationGamepads()
    for _, gamepad in pairs(navGamepads) do
        local supportedKeyCodes = UserInputService:GetSupportedGamepadKeyCodes() --//ERROR LINE
     
        for _, keycode in pairs(supportedKeyCodes) do
            if (keycode == Enum.KeyCode.ButtonX) then
                ContextActionService:BindAction("SampleAction", actionHandler, false, Enum.KeyCode.ButtonL1)
            end

The error is Argument 1 missing or nil , i don’t know what i should change and that stuff, thanks for reading

GetSupportedGamepadKeyCodes requires a UserInputType referencing what Gamepad, ie. Enum.UserInputType.Gamepad1 would be the first plugged in Gamepad.

Now there’s not any error, but i can’t do the function in the keyboard:

if (keycode == Enum.KeyCode.E) then
                ContextActionService:BindAction("SampleAction", actionHandler, false, Enum.KeyCode.E)
            end

Which should print something

E can’t possibly be a SupportedGamepadKeyCode, unless this is from another piece of code?


    local UserInputService = game:GetService("UserInputService")
    local ContextActionService = game:GetService("ContextActionService")
     
    local function actionHandler(actionName, inputState, inputObj)
    	if inputState == Enum.UserInputState.Begin then 
    		print("Script is working, now write something else here dumo")
    	end
    end
     
    local navGamepads = UserInputService:GetNavigationGamepads()
    for _, gamepad in pairs(navGamepads) do
        local supportedKeyCodes = UserInputService:GetSupportedGamepadKeyCodes(Enum.UserInputType.Gamepad1)
     
        for _, keycode in pairs(supportedKeyCodes) do
            if (keycode == Enum.KeyCode.ButtonX) then
                ContextActionService:BindAction("SampleAction", actionHandler, false, Enum.KeyCode.ButtonL1)
            end
            if (keycode == Enum.KeyCode.E) then
                ContextActionService:BindAction("SampleAction", actionHandler, false, Enum.KeyCode.E)
            end
        end
    end

This is the full script

Yeah, Enum.KeyCode.E isn’t a SupportedGamepadKeyCode.
You could just add it to the inputs of the BindAction in the first:

ContextActionService:BindAction("SampleAction", actionHandler, false, Enum.KeyCode.ButtonL1, Enum.KeyCode.E)

The script is not working for me, did i made something wrong?:

if (keycode == Enum.KeyCode.ButtonX) then
     ContextActionService:BindAction("SampleAction", actionHandler, false, Enum.KeyCode.ButtonL1,Enum.KeyCode.E)
end

Do you have a Gamepad plugged in?

No, i want to keep this compatible for gamepads and keyboards.

This code would only run if a Gamepad was plugged in, honestly there’s no point in iterating to check if they do have the KeyCode supported.

Just Bind it anyways, it won’t make any difference and will function for everyone.