UserInputService acting very weird

UserInputService is being weird, when Im holding F, it dosent detect the A key as a input? But it detects all the other keys??

Heres a clip of it

https://medal.tv/games/roblox/clips/vhuKp0YnmbpvZ/d1337xhtPOm1?invite=cr-MSxwV0IsODE2MTQ0ODEs

In the clip, when im blocking, I should be able to roll. But I cant roll to the left because its not detecting the “A” key.

1 Like

switch:

if UIS:IsKeyDown(Enum.KeyCode.A) then

to:

elseif UIS:IsKeyDown(Enum.KeyCode.A) then

that wont work, the script will get a error

How many keys are you holding down? Your keyboard might not support more than 3 keys at a time.

2, and spamming Q. Im holding A and F down while spamming Q

dosent work

That is pretty odd. What if you swap A and D? Does D still work? I’m not sure why it would change, but it’s worth a try just to rule out some issue with the control flow that we’re not seeing.

If all else fails, you should be able to track the states of the WASD keys yourself by using InputBegan and InputEnded. If that still doesn’t work, you can add some prints to see if the A key is getting an unexpected InputEnded when you press Q - if so, it’s the keyboard issue I mentioned.

Maybe read my post again and see what i am talking about.

That isn’t the problem here. IsKeyDown(A) should return true if the A key is down regardless. OP here is trying to check the state of the A key when the Q key is pressed, not the other way around.

A still dosent work.

Ill test with my friends too see if the keyboard if the problem, but I dont think it is

elseif (input.KeyCode == Enum.KeyCode.A) then

try using that instead of a KeyDown function hm

The entire thing is in a Q Enum loop, you’re aware of that right?

Are you totally sure the “Left” event works, then? I guess it would’ve printed “A” before though.

I guess you could try tracking the key states yourself then.

local keyStates = {}
local keysToTrack = { [Enum.KeyCode.A]=true, [Enum.KeyCode.D]=true, [Enum.KeyCode.W]=true, [Enum.KeyCode.S]=true }
UIS.InputBegan:Connect(function(inputObj, processed)
     if processed then return end
     if keysToTrack[inputObj.KeyCode] then
        keyStates[inputObj.KeyCode] = true
    end
    if inputObj.KeyCode == Enum.KeyCode.Q then
        if keyStates[Enum.KeyCode.A] then
             game.ReplicatedStorage.RemoteEvents.RollEvent:FireServer("Left")
        elseif keyStates[Enum.KeyCode.D] then
             --so on
       end
end)
UIS.InputEnded:Connect(function(inputObj, processed)
     if keysToTrack[inputObj.KeyCode] then
        keyStates[inputObj.KeyCode] = false
    end
end)

It’s not working because for each key press the function runs seperately so Input.KeyCode cannot be Q and A simultaneously, instead you can check if you are holding Q and then check if you pressed A while you are holding Q. Here is some code:

local UserInputService = game:GetService("UserInputService")

local HoldingQ = false

UserInputService.InputBegan:Connect(function(Input,GPE)
	if GPE then return end
	if Input.KeyCode == Enum.KeyCode.Q then
		HoldingQ = true
	elseif Input.KeyCode == Enum.KeyCode.A and HoldingQ then
		print("Holding Q and pressed A")
	end
end)

UserInputService.InputEnded:Connect(function(Input)
	if Input.KeyCode == Enum.KeyCode.Q then
		HoldingQ = false
	end
end)

You can also shorten this code by including UserInputSerivce:IsKeyDown(keyCode) like this:

local UserInputService = game:GetService("UserInputService")

UserInputService.InputBegan:Connect(function(Input,GPE)
	if GPE then return end
	if Input.KeyCode == Enum.KeyCode.A and UserInputService:IsKeyDown(Enum.KeyCode.Q) then
		print("Holding Q and pressed A")
	end
end)

Did you read the original post at all?

That wont work, how the roll works is that somebody presses Q, while holding down one of the four keys WASD

that wont work, the roll script works by sombody pressing Q while hold one of the four WASD, WASD is for the direction and pressing Q just activates the roll

I will try this

I need more characters

dosent work, im gonna still keep the code though because it looks nice. I was testing with the search bar in google. It might be a keyboard issue, not entirely sure though, have to wait for my friend to get on to test with his keyboard