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

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

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

✓ Accepted answer

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!)

2 comments

0

it says that InputBegin is not a valid member of UserInputService

0

sorry I always make this mistake its input began

An easier way of doing that ^..

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

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

This discussion is preserved as it was. New answers, comments, and votes are closed.