Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Is there a way to detect if somebody presses the key 'E'?

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!

2 comments

0

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

0

That link goes nowhere

2 answers

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.