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?
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)
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)