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

How would i detect what a player presses on the keyboard?

Asked by 9 years ago

I have seen games where you press "E" to eat and stuff, is there a thing I could use to detect what players press on their keyboards?

2 answers

Log in to vote
0
Answered by
Hero_ic 502 Moderation Voter
9 years ago

You can use the UserInputService ! http://wiki.roblox.com/?title=API:Class/UserInputService Example:

game:GetService("UserInputService").InputBegan:connect(function(input,proc)
    if not proc then --checks if not using chat
        if input.KeyCode == Enum.KeyCode.E then
            --Do stuff.
        end
    end
end)

hope this helped! ~KIHeros :) (If it did please accept!)

0
it says that InputBegin is not a valid member of UserInputService connor12260311 383 — 9y
0
sorry I always make this mistake its input began Hero_ic 502 — 9y
Ad
Log in to vote
0
Answered by 9 years ago

An easier way of doing that ^..

wait()
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()

mouse.KeyDown:connect(function(key)
    print(key)
end)

Answer this question