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 8 years ago
Edited 8 years ago

Here is what I got.

01local HitAKey = game.Players.LocalPlayer:GetMouse().KeyDown
02local Name = game.Players.LocalPlayer.Name
03 
04HitAKey:connect(function(key)
05    if key == 'e' or 'E' then
06        print(Name.." has pressed E!")
07    elseif key == 'q' or 'Q' then
08        print(Name.." has pressed Q!")
09    end
10end)

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 — 8y

1 answer

Log in to vote
2
Answered by 8 years ago

use UserInputService

Make sure it's in a local script!

01game:GetService("UserInputService").InputBegan:connect(function(input)
02    local playerName = game.Players.LocalPlayer.Name
03 
04    if input.KeyCode == Enum.KeyCode.Q then
05 
06        print(playerName.."Has pressed Q")
07 
08    elseif input.KeyCode == Enum.KeyCode.E then
09 
10        print(playerName.."Has pressed E")
11 
12    end
13end)
0
How can I make it so it does something if u press 2 keys? SH_Helper 61 — 8y
Ad

Answer this question