Hey, guys, I have just started to get into scripting recently and got stuck for a little while on the UserInputService where I'm trying to get the keyboard input the player presses on their keyboard. I put the local script into StarterPlayerScripts and looked at the API Reference on UserInputService and their code didn't work so I was wondering if anybody could help me out. The error message on the line where i declare the local keypressed variable and says: "KeyCode is not a valid member of InputObject" even though Object Brower has Keycode listed under InputObject. If anyone could help me out if would be a huge help. Thanks! (The following lines starting with 'userinputservice' is my code. I don't know why it doesn't have those in coding lines as well).
userinputservice = game:GetService('UserInputService')
userinputservice.InputBegan:Connect(function(input,gameProcessed)
if input.UserInputType == Enum.UserInputType.Keyboard then local keypressed = input.Keycode print(keypressed) end
end)
Here try this
function onKeyPress(inputObject, gameProcessedEvent) if inputObject.KeyCode == Enum.KeyCode.F then --change f to the key you want make sure that letter is caps :D-- print(Player has pressed F)
userinputservice = game:GetService('UserInputService') userinputservice.InputBegan:Connect(function(input,gameProcessed) if input.UserInputType == Enum.UserInputType.Keyboard then local keypressed = input.KeyCode print(keypressed) end end)
KeyCode is caps-sensitive so if you just type Keycode, the game isn't going to recognize it.