Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

KeyDown is not working correctly, how do i fix?

Asked by 7 years ago
Edited 7 years ago

Here is what I got.

local HitAKey = game.Players.LocalPlayer:GetMouse().KeyDown
local Name = game.Players.LocalPlayer.Name

HitAKey:connect(function(key)
    if key == 'e' or 'E' then
        print(Name.." has pressed E!")
    elseif key == 'q' or 'Q' then
        print(Name.." has pressed Q!")
    end
end)

But when I press any keyboard button, like A, it prints "Player1 has pressed E!" But it still prints that if I press W, A, S, D keys again!

0
this is NOT a request site Volodymyr2004 293 — 7y

1 answer

Log in to vote
2
Answered by 7 years ago

use UserInputService

Make sure it's in a local script!

game:GetService("UserInputService").InputBegan:connect(function(input)
    local playerName = game.Players.LocalPlayer.Name

    if input.KeyCode == Enum.KeyCode.Q then

        print(playerName.."Has pressed Q")

    elseif input.KeyCode == Enum.KeyCode.E then

        print(playerName.."Has pressed E")

    end
end)
0
How can I make it so it does something if u press 2 keys? SH_Helper 61 — 7y
Ad

Answer this question