If Player Dies, They Get Kicked

Hello, um this is my first time here. I’m looking a script when someone dies, they get kicked from the game

Idk if yall can help me!!

This is my script

local player = game.Players.LocalPlayer
local character = player:FindFirstChild("Character")
local humanoid = character:WaitForChild("Humanoid")

if humanoid:TakeDamage(100) then
	player:Kick("Come Back Again")
	wait(5)
end

I want to know where to place the script.

1 Like

humanoid.Died:Connect(function()
player:Kick(“come back again”)
end)

Put this script in StarterCharacterScripts. But change it to the following:

local player = game:GetService("Players").LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")

humanoid.Died:Connect(function()
	player:Kick("Come Back Again")
end)
5 Likes

I will test it in the morning. thank you!!

just some reasoning:
your script wouldn’t work (your first script) because its checking if the humanoid all at once took 100 damage, which just means that there has to be an attack or something that does 100 damage all at the same time.

1 Like

This won’t work, “Character” isn’t a child of the “Player” instance, it’s a property of the “Player” instance, the function named “FindFirstChild” attempts to find the first child which has a name matching the string value passed as the first argument to the function, instead the following will work:

local players = game:GetService("Players")
local player = players.LocalPlayer or players.PlayerAdded:wait()
local character = player.Character or player.CharacterAdded:wait()
local humanoid = character:WaitForChild("Humanoid")

humanoid.Died:Connect(function()
	player:Kick("You died!")
end)
4 Likes

It worked thank you very much.

2 Likes