You can write your topic however you want, but you need to answer these questions:
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.
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)
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.
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.
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
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.