Binding Right Click to Context Action Service fix or alternative?

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

  1. What do you want to achieve? Keep it simple and clear!

I am making a combat system where you right click and it does a strong punch.

  1. What is the issue? Include screenshots / videos if possible!

It will not let me drag my camera around

  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?

I tried using mousebutton2 and userinputservice but they did not work for some odd reason.

This is my current code:

[quote=“ScarletHypernova, post:1, topic:1131241, full:true”]
You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!

I am making a combat system where you right click and it does a strong punch.

  1. What is the issue? Include screenshots / videos if possible!

It will not let me drag my camera around

  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?

I tried using mousebutton2 and userinputservice but they did not work for some odd reason.

This is my current code: (sorry i cant do a codeblock on phone)

local function onClicked(action, state, obj)
if action == “RightClick” then
remote:FireServer()
end
end

From what you described, it sounds like your action is being binded at a higher priority than the camera drag’s action. You can view binded actions by pressing F9 in game.

UserInputService should solve this problem, though you said it didn’t work. If the code didn’t work but the camera still did, you might have used the gameProcessed bool as a debounce on accident.

Try this code:

local remote --Set to RemoveEvent
UserInputService.InputBegan:Connect(function(input)
	if input.UserInputType == Enum.UserInputType.MouseButton2 then
		print("Right Click!")
		remote:FireServer()
	end
end

Oh, I used isTyping on the user input service method I tried, is that bad?

Aside from answering your question, are you going to be changing the camera to lock to mouse movement without right clicking with this mechanic? I feel, from a player standpoint, that it would be annoying to have to right click for looking around and using a strong punch.

1 Like

Add
return Enum.ContextActionResult.Pass
At the end of the onClicked function, otherwise it won’t use right click for any other action (that’s why the camera doesn’t rotate)

14 Likes

Also, it is in a tool so it checks if it clicks or not and I’m still an amateur. Plus, they can use shift lock too.

1 Like