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

How Do I Do A Key Pressed Function?

i'm Making A Ship That If Player Is Seated And Is Pressing Key "Something" So It Moves

1 answer

✓ Accepted answer

You should use UserInputService as KeyDown event is deprecated.

local uis = game:GetService:("UserInputService")
uis.InputBegan:Connect(function(input)
if input.KeyCode == Enum.input.KeyCode.F then-- replace F with whatever key you'd like
	print("hi")
end)

UserInputService is recommended for client input because of it's wide range of uses across multiple platforms.

4 comments

0

is there any other way?

2

you should not use another way, UserInputService is the best way to gather input from the client currently

0

But, if you were going to: https://developer.roblox.com/api-reference/event/Mouse/KeyDown but be aware that it doesn't work with all keys

0

alright thank you!

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