How to detect when they die?

Hello! Im making a boxing system, where each players fight, and only one will remain at the end of it.

Currently, when the 2 players fight, and Player1 loses, they don’t get teleported back to each of their spawnpoints for another round.

In total, there should be 3 rounds, but after one player dies, the script is just not teleporting them.

Can someone please help me? I would greatly appreciate it!

Thank you.

function round(num, player)
	if num == 0 then
		game.ReplicatedStorage.CountdownFight:FireClient(game.Players:FindFirstChild(Player1.Value))
		game.ReplicatedStorage.CountdownFight:FireClient(game.Players:FindFirstChild(Player2.Value))
		
		
		game.Players:FindFirstChild(Player1.Value).Character.Humanoid.HealthChanged:Connect(function()
			if game.Players:FindFirstChild(Player1.Value).Character.Humanoid.Health <= 0 then
				player1death += 1
				print('player 2 won')
				task.wait(3)
				--tp players for another round
				local Character1 = game.Players:FindFirstChild(Player1.Value).Character
				local HumanoidRootPart1 = Character1:FindFirstChild("HumanoidRootPart")
				local Humanoid1 = Character1:FindFirstChildWhichIsA("Humanoid")
				local Character2 = game.Players:FindFirstChild(Player2.Value).Character
				local HumanoidRootPart2 = Character2:FindFirstChild("HumanoidRootPart")
				local Humanoid2 = Character2:FindFirstChildWhichIsA("Humanoid")

				if HumanoidRootPart1 and Humanoid1 then
					HumanoidRootPart1.CFrame = Spawnpoints.Player1.CFrame
					roundnum += 1
				elseif HumanoidRootPart2 and Humanoid2 then
					HumanoidRootPart2.CFrame = Spawnpoints.Player2.CFrame
					roundnum += 1
				end
			end
		end)

instead of using:

if game.Players:FindFirstChild(Player1.Value).Character.Humanoid.Health <= 0 then
-- Stuff
end

you could fire a function whenever the selected humanoid dies by using this:

game.Players:FindFirstChild(Player1.Value).Character.Humanoid.Died:Connect(function()
	-- Stuff
end)

I hope this helps :smiley:

Im using a task.wait(3) so that after 3 seconds, they are hopefully respawned and should be teleported back. But there are also those laggy players whos average ping is 7,000. How would I make it so that it detects when those players respawn?

You could use:

repeat
task.wait(1)
until Player1.Character.Humanoid.Health == 100
-- Stuff