Roblox How To | How to Detect User Input

Welcome to my new Series, Roblox How To, Today StarJ3M will be tuning in to teach you! How to detect player input!


Part 1 - What is Player Input?

Before trying to Detect player input, we need to learn… What is Player Input?. Player input is basically, Player Input can be a players Keyboard, Whenever a client clicks a key on ROBLOX on their computer, it detects player input and makes something happen! Without player input, you cant run, jump, climb, walk, or emote! But with Player Input, You can do just that!

Player Input can be seen being used in a lot of games, Like for an example, If we press 1 and theirs a available tool in our inventory that has their key bind set to 1 then, we can equip it by default! or, Lets say their is a shift to spring, The Game Developer would Detect The Players input and check if their holding down shift or pressed it so then they can set their humanoids Walkspeed Value to whatever they like! Or like in that one really cool ROBLOX game cald Parkour, theirs a key bind to make a light source on your glove which is the “R” Key!


Part 2 - What would the Game Developer do to Get The Players Input?

You, being the game Dev will have to use a Service cald… Drumble please…



|!UserInputService!|

User input Service is a CLASSIFIED Service, It is used to detect player input, How do you use it you may say? Well lets go to part 3 for that!

Part 3 - How do I use UserInputService?

Well, to use it first we need to define user input, lets do it like this:

local UIS = game:GetService("UserInputService") -- Defining the Service

Next, we can call the service and create a function! Lets make a Easier way for the player to reset!

local UIS = game:GetService("UserInputService")

local Players = game:GetService("Players") -- Players Service

local player = Players.LocalPlayer -- Getting the Player

local character = player.CharacterAdded:Wait() -- The Players Character

local Humanoid = character:WaitForChild("Humanoid") -- Their Humanoid

UIS.InputBegan:Connect(function(input, GPE) -- This will detect the input, Connecting to the input that got in, GPE = Game Processed Event and is if the game processed it and if the player is busy, like typing in the chat for an example
	if input.KeyCode == Enum.KeyCode.Backspace then -- Making a if statement to ask if the players input is == to input
		Humanoid.Health = 0 -- Kills The Player
	end
end)

As you can see, now the player can simply reset by clicking backspace

This is part 1 on How to Detect Player Input!

Please consider liking this post and maybe sharing it to other who need it, It would make me happy considering I put lots of time and hard work into this!

Other Tutorials…

Create a Simple Shift To Sprint

22 Likes

You didn’t specify what does GPE mean for the beginners.

This isn’t even a detailed tutorial about UserInpurService. You didn’t explain enough.

7 Likes

I didn’t, Sorry, I thought I did!

Sorry about that to, I will try to put more detail and explain more. Thanks for the comment!

When I have the time, I will fix it!

1 Like

Definitely agree with @ItzMeZeus_IGotHacked, this tutorial needs more descriptions on how UIS works.

I would recommend going through some of the events of UIS such as explaining how InputBegan and other frequently used events in-depth.

And finally, you should mention (in case there are any new developers reading) that UIS only works on the client, meaning it can be only used with a local script in StarterPlayerScripts.

Keep up the good work!

3 Likes

Ideally, the correct place for scripts like these for “newbie” scripters, developers is StarterCharacterScripts.

2 Likes