What I'm trying to say is that for instance, if somebody pressed the"E" key on their keyboard, they would get a gun or something. Is there any way to detect if someone pressed the key? Thank you!
Is there a way to detect if somebody presses the key 'E'?
2 answers
You need to use a LocalScript to access the PlayerMouse Object, and then you can set up a KeyPressed Event and check what key the pressed.
There is a KeyDown event
Put a LocalScript inside the StarterPack
Player = game.Players.LocalPlayer
Mouse = Player:GetMouse()
function PressedE(key)
end
Mouse.KeyDown:connect(PressedE)
Now the above code is only a way to start it off it doesn't have any relation with key e yet
Player = game.Players.LocalPlayer
Mouse = Player:GetMouse()
function PressedE(key)
Key = key:lower() --I'm just used to doing this..I don't think you have to
if Key == "e" then
print("Key e was pressed")
end
end
Mouse.KeyDown:connect(PressedE)
Now the above code detects that e was pressed and it prints to the output.
Here is it in other words:
The Player = a Local Player Mouse is Getting the Mouse
If the Key pressed is e then print to the output
If the the Mouse's Key is pressed it will connect the function PressedE. And that function detects if e was pressed. So that's basically how you do it. Sorry if it's a bit sloppy.
I'd be glad if this helped :)
This discussion is preserved as it was. New answers, comments, and votes are closed.

2 comments
Why won't the link come out properly? http://wiki.roblox.com/index.php?title=KeyDown_(Event) Hope it does now.
That link goes nowhere