Script doesn't detect keyboard Arrow Keys

hello, i’m trying to use user input service to detect if left, up, and down right arrow keys are being pressed. Only the Up and Down keys are working/ being detected. Please how do i fix the left and right arrow keys?
Any help is appreciated
Script -

local uis = game:GetService("UserInputService")

uis.InputBegan:Connect(function(input, gameProcessed)
	if gameProcessed then return end 

	if input.KeyCode == Enum.KeyCode.Left then
		print("Left")
	elseif input.KeyCode == Enum.KeyCode.Right then
		print("Right")
	elseif input.KeyCode == Enum.KeyCode.Up then
		print("Up")
	elseif input.KeyCode == Enum.KeyCode.Down then
		print("Down")
	end
end)

Also if i have to disable left and right for camera movement for it to work, how do i disable it?

1 Like

if should be if not gameProcessed then This is because it will only return as false when the player is typing on something or is not on the game.

local uis = game:GetService("UserInputService")

uis.InputBegan:Connect(function(input, gameProcessed)
	if not gameProcessed then return end 

	if input.KeyCode == Enum.KeyCode.Left then
		print("Left")
	elseif input.KeyCode == Enum.KeyCode.Right then
		print("Right")
	elseif input.KeyCode == Enum.KeyCode.Up then
		print("Up")
	elseif input.KeyCode == Enum.KeyCode.Down then
		print("Down")
	end
end)

That’s the other way around. (As seen in the documentation)


2 Likes

1- is this a local script or just a normal script
2- where is the script located

2 Likes

thanks, but now the left and right works ,making the up and down to stop working

1 Like

but i found a fix for it, Thanks to everyone for helping

local uis = game:GetService("UserInputService")

uis.InputBegan:Connect(function(input, gameProcessed)
	if not gameProcessed and gameProcessed then return end 

	if input.KeyCode == Enum.KeyCode.Left then
		print("Left")
	elseif input.KeyCode == Enum.KeyCode.Right then
		print("Right")
		if gameProcessed then return end 
	elseif input.KeyCode == Enum.KeyCode.Up then
		print("Up")
	elseif input.KeyCode == Enum.KeyCode.Down then
		print("Down")
	end
end)
1 Like