I'm not quite used to UserInputService, I've only been using the Mouse object. Can someone show me how to do something like this with UserInputService? Sorry if it sounds like a request, but I'm lost.
player = game.Players.LocalPlayer mouse = player:GetMouse() mouse.KeyDown:connect(function(key) if key == "f" then print("sup") end end
Due to KeyDown becoming deprecated, using UserInputService is the only way to get the press of a key. In order to use UserInputService, you must first use :GetService()
and from there you can use the InputBegan
event so that you can tell when the person gives any form of input. From here you can just use a simple function with parameters to figure out which key they pressed. You will need the KeyCode List in order to find the KeyCodes of keys that you don't know.
Please note that this is not a complete script but is merely the function that you would use to find a pressed key.
game:GetService("UserInputService").InputBegan:connect(function (input, _) -- recognizes input is being given if input.KeyCode == enum.KeyCode.W then -- checks to see if the key pressed was the W key print("the player pressed W") end end)