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

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

Asked by 10 years ago

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!

0
Why won't the link come out properly? http://wiki.roblox.com/index.php?title=KeyDown_(Event) Hope it does now.   M39a9am3R 3210 — 10y
0
That link goes nowhere ipiano 120 — 10y

2 answers

Log in to vote
1
Answered by
ipiano 120
10 years ago

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.

http://wiki.roblox.com/index.php?title=PlayerMouse

Ad
Log in to vote
1
Answered by 10 years ago

There is a KeyDownevent Put a LocalScriptinside 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 :)

Answer this question