Having issues with ContextActionService

Hello! I am trying to make a dragging and rotating system. Recently I finished the dragging, and started to work on rotating. I made this simple function to see which key I pressed or released:

local function Rotate(actionName, inputState, inputObject)
	if inputState == Enum.UserInputState.Begin and inputObject.KeyCode == Enum.KeyCode.W then
		rotatingForward = true
		print("w start")
	elseif inputState == Enum.UserInputState.End and inputObject.KeyCode == Enum.KeyCode.W then
		rotatingForward = false
		print("w stop")
	elseif inputState == Enum.UserInputState.Begin and inputObject.KeyCode == Enum.KeyCode.S then
		rotatingBackward = true
		print("s start")
	elseif inputState == Enum.UserInputState.End and inputObject.KeyCode == Enum.KeyCode.S then
		rotatingBackward = false
		print("s stop")
	elseif inputState == Enum.UserInputState.Begin and inputObject.KeyCode == Enum.KeyCode.D then
		rotatingRight = true
		print("d start")
	elseif inputState == Enum.UserInputState.End and inputObject.KeyCode == Enum.KeyCode.D then
		rotatingRight = false
		print("d stop")
	elseif inputState == Enum.UserInputState.Begin and inputObject.KeyCode == Enum.KeyCode.A then
		rotatingLeft = true
		print("a start")
	elseif inputState == Enum.UserInputState.End and inputObject.KeyCode == Enum.KeyCode.A then
		rotatingLeft = false
		print("a stop")
	end
end

However, every print that is supposed to print out “key pressed” upon key press fails. HOWEVER, It is worth mentioning that this function can only run while you are holding an object (aka holding down your left mouse button) and then pressing left CTRL. Once you release the mouse button and try to press the keys again, the prints suddenly start to work.

Why is this happening and how can I fix it?

*Actually, the D key works just fine

Turns out CTRL + W, CTRL + A and CTRL + S are all shortcuts, and because of them the script didn’t work properly. Replacing CTRL with SHIFT fixed the issue.

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