ContextActionService Problem

SO Im trying to detect when the player holds and let’s go and it isn’t working as intended, any ideas whats going on their isnt anything printing in the output

Here is the code :

function SwingL(state)
	if state == Enum.UserInputState.Begin then
		print("Holding")
	elseif state == Enum.UserInputState.End then
		print("Not holding.")
	end
end


game.ContextActionService:BindAction("SwingLeft", SwingL, true)

What is state that you are passing as argument is it a parameter if not then aren’t you supposed to pass it?

I havent used contextactionservice much so I dont even know

You aren’t binding anything to SwingL, so the script is never going to fire. Try binding it to a key like so:

game:GetService("ContextActionService"):BindAction("SwingLeft", SwingL, true, Enum.KeyCode.L)

You are also improperly defining the “State” in your SwingL function, add this as an amendment:

function SwingL(actionname, state)
	if state == Enum.UserInputState.Begin then
		print("Holding")
	elseif state == Enum.UserInputState.End then
		print("Not holding.")
	end
end

The first argument through a ContextAction bind is always the ActionName, not the InputState, the InputState is always passed as the second argument.

I am binding it to a mobile button, and I tried your method and it didnt work either
image

Reference the edit I just made to my original post, had an oversight and updated the post accordingly.

Alright I havent scrolled up yet let me do that, wow it worked what do ya know thanks alot @TerryMichaelBrunk, big help keep it up