Need help with ContextActionService

I am making a gun system for both mobile and pc and I need to know how to track events on ContextActionService buttons if it’s possible. Like, in common ScreenGui buttons you can check for MouseButton1Down and MouseButton1Up, but how to do it with ContextActionService?
I could try using UserInputService's Mouse1Down and Mouse1Up but then it will be not available for mobile.
Thanks in advance.

Can I please get an example on how to do this?

You should check BindAction() function, you provide a function and you can create a mobile button with it. You can also bind keycodes.

1 Like

Don’t know if this is what you’re lookin’ for but here is something that might of use:

This works for PC
Mobile as well as it create a button for mobile devices

To test it out, just stuff it into a Local Script inside StarterCharacterScripts

local contextActionService = game:GetService("ContextActionService")

local function ButtonThing(action, inputState)
	if action == "Hold"  and inputState == Enum.UserInputState.Begin then
		print("Holding Button")
	else
		print("Not Holding Button")
	end
end

contextActionService:BindAction("Hold", ButtonThing, true, Enum.UserInputType.MouseButton1)
--the [true boolean] creates a button for mobile! If [false] it wont create one!!
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.