How to pass arguments into a action bind?

I am trying to pass arguments into a function that is bind to an action. However, I keep getting the error that Argument 2 is missing. I know that the function already passes three arguments, but it comes from binding the action itself.

I’ve been trying to find existing threads and look at the documentation, but I still couldn’t figure out how to fix this.

-- Function to bind
local function foo(actionName, inputState, inputObject,target)
	-- Code hidden
end

-- I want to pass target as an arguement
ContextActionService:BindAction("Bar",foo(target),true,Enum.KeyCode.E)

You can’t, so you will need to pass a literal, then pass it yourself.

local function foo(target)
    -- stuff
end

ContextActionService:BindAction("Bar", function(action_name, input_state, input_object)
    foo(target)
end, true, Enum.KeyCode.E)
4 Likes

Will foo still take in the three parameters?

No, it would only get 1, you would use the action name, inptu state, input object, from the literal function object

1 Like