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!