How do I remove ButtonR2 firing clicked events

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Whenever I bind an action (ContextActionService) to Enum.UserInputType.MouseButton1, I want it to not fire on controllers when ButtonR2 is pressed.

  2. What is the issue? Actions binded to MouseButton1 also fire when ButtonR2 is pressed on a controller. In this script, it will fire when: the left mouse button is clicked (good), when the mobile button is pressed (good), and when R2 on a controller is pressed (bad).

local contextActionService = game:GetService("ContextActionService")

local function clickAction(actionName, actionState, inputObj)
	if actionState.Name == "Begin" then
		print("function ran")
	end
end

contextActionService:BindAction("ClickAction", clickAction, true, Enum.UserInputType.MouseButton1)
  1. What solutions have you tried so far? I’ve looked on the DevForum and haven’t found anything similar to my problem. I’ve also tried binding R2 to something else, but R2 still fires as the mouse. Strangely, when there’s a gui where the mouse would be, R2 does not trigger MouseButton1.

Any resources/info is greatly appreciated.

4 Likes

Check if inputObj is the same if mouse button or R2 on controller is activated. Just add print(inputObj) and look at the output.

4 Likes

First off, inputObj is not a single value. It’s an Instance containing two properties, UserInputType and KeyCode. I printed both properties, and the R2 is being detected as a mouse, down to the UserInputType & the KeyCode.

3 Likes

have you tried comparing UIS:GetLastInputType? i’d imagine doing something like:

local function WasGamepad(): boolean
	return UIS:GetLastInputType() == Enum.UserInputType.Gamepad1
	-- return UIS:GetLastInputType().Name:find("Gamepad") ~= nil -- if game uses multiple gamepads
end

i do comparisons similar to this in order to correctly determine the true input device

3 Likes

Question, is this for a tool or a gui object? Either way, both have an event called “Activated” that works universally for all devices.

Tool.Activated:Connect(function()
-- Do stuff
end)

GuiButton.Activated:Connect(function()
-- Do stuff
end)

Hope this helps!

1 Like

This is a tool for a script. The reason I need R2 to be separate from the mouse is because the tool has a special ability, and I want that ability to be binded to R2.

Thank you for all the help, I ended up doing something else.

I edited the PlayerModule for the gamepad and disabled any R2 bindings. It now works perfectly!
image

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