Repeatable Player Killing Method

Hello, I am trying to make a kill system that kills the player even after they have respawned.

I am currently using Humanoid.Health to kill the player,

local localPlayer = game:GetService("Players").LocalPlayer
local char = localPlayer.Character or localPlayer.CharacterAdded:Wait()

while wait(1) do 
	local partParent = char
	local humanoid = partParent:FindFirstChild("Humanoid")
	humanoid.Health = humanoid.Health - 10
end

However, this does not repeat after the character has died once and respawned, as shown in the video below.

I have been looking all over for a solution, Thanks in advanced!

Some Clarification

Now I actually dont want to kill the player exactly like I showed in the video, I am simply using a new, blank place to show this. This kill system will be implemented into an underwater/oxygen depletion system where I noticed that after killing the player once, (even while the oxygen level was at zero) the Humanoid.Health would not kill the player again. Thanks!

It’s in starter player scripts, so the code only runs once.

Use player.CharacterAdded to get the new character and new humanoid after respawn. Currently it’s subtracting the old humanoid which is destroyed hence not doing anything.

1 Like

Server method:

game.Players.PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Connect(function(Character)
		local Humanoid = Character:WaitForChild("Humanoid")
		repeat
			Humanoid.Health -= 10
			task.wait(1)
		until Humanoid.Health <= 0
	end)
end)

Client method:

local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")

repeat
	Humanoid.Health -= 10
	task.wait(1)
until Humanoid.Health <= 0

Either one works, just know health doesn’t replicate to the server if you do it on the client. And also try to use task.wait() instead of wait() now.

Roblox has a nice method off of Humanoid called :TakeDamage() so instead of having to do all the long math stuff, you can just call that method and boom! Damage!

But like @dthecoolest said, you should place this in StarterCharacterScripts or use player.CharacterAdded to repeat this each time the character is added.

And like @alphajpeg said

Just use +=, -=, /=, and *= and you dont need to do Value = Value + 1, just Value += 1

That works too, but Roblox specifically made a function just for making a Humanoid take damage.

Yeah you should still use TakeDamage(), just thought I’d let you know about the math part.

It’s not me you have to tell about it, I use it in all my code. I’ve been using it in my code since 2006, glad Roblox finally added the ability to use it.

Thanks everyone! This has really helped me! @dthecoolest @alphajpeg

Also thanks @MrLonely1221 I wasn’t aware of :TakeDamage() This is a much easier way of killing the player :slight_smile:

1 Like