Hello, in this tutorial I will be teaching you how to make a Kill bind. But before that, let me educate the people who don’t know what a Kill bind is.
A Kill bind simply put, is a key that when pressed kills your character.
This can be used to allow players to just press a key rather then having to reset via the Roblox menu.
Now with that out of the way, onward!
Right here is the Variables
local UserInputService = game:GetService("UserInputService")
local Character = script.Parent
local Humanoid = Character:WaitForChild("Humanoid")
A variable is a bit of code, usually at the start of the script that allows you to list something under a certain name, get a service ect.
I’m not going to teach you everything about scripting today because we simply just don’t have time.
Now lemme explain this code.
local UserInputService = game:GetService("UserInputService")
local Character = script.Parent
local Humanoid = Character:WaitForChild("Humanoid")
Local UserInputService = game:GetService(“UserInputService”)
is a line of code which grabs the UIS service, which is used for keyboard inputs, which is what we’re using.
The two other variables are getting the Character and the Humanoid
Both of which we will also need.
The last part of this script is:
UserInputService.InputBegan:Connect(function(key)
if key.KeyCode == Enum.KeyCode.LeftAlt then
Humanoid.Health = 0
end
end)
This might be a little overwhelming for a very new scripter, so lemme break this down to easier to understand words.
The first part of this script is Checking if the key is pressed and will return true if pushed.
The next line is defining what key is the key that will kill the player.
And the final important line is going to the Players Humanoid and setting the health to zero.
The finished script:
local UserInputService = game:GetService("UserInputService")
local Character = script.Parent
local Humanoid = Character:WaitForChild("Humanoid")
UserInputService.InputBegan:Connect(function(key)
if key.KeyCode == Enum.KeyCode.LeftAlt then
Humanoid.Health = 0
end
end)
This is my first Roblox tutorial so I might have gotten some things wrong, please do give feedback if I do mess something up.
Also make sure the Local script is placed in Starter Character Scripts