roblox
Tutorial page
This article is an intermediate tutorial.
GUI
This page is a tutorial about GUI.

In this tutorial, we will go over making a basic kill button. In order to complete this tutorial, you will need to have a basic knowledge with GUIs. Some helpful gui teaching links are shown below.

Lets begin!

The first step is to make the gui. To do this tutorial, we are going to put a TextButton light iconTextButton dark iconTextButton into a ScreenGui light iconScreenGui dark iconScreenGui, then insert a LocalScript light iconLocalScript dark iconLocalScript into the button. Your hierarchy should look like this.

Open up the LocalScript, delete all the current code. Now, we can start by defining variables.

local player = game.Players.LocalPlayer
player.CharacterAdded:Wait()
local character = player.Character

Now, we can hook up our event.

local player = game.Players.LocalPlayer
player.CharacterAdded:Wait()
local character = player.Character
script.Parent.MouseButton1Click:Connect(function()

end)

We have our event hooked up, but we need to make it actually kill the player. To do this, we find the Humanoid light iconHumanoid dark iconHumanoid object inside of the player's character, and set it's health to 0.

local player = game.Players.LocalPlayer
player.CharacterAdded:Wait()
local character = player.Character
script.Parent.MouseButton1Click:Connect(function()
    local humanoid = character:FindFirstChildOfClass("Humanoid")
    if humanoid then
        humanoid.Health = 0
    end
end)

This button will now instantly kill any player who presses it.