When a player dies the body touches the next checkpoint and is on that checkpoint instead of respawning back the the previous checkpoint

I am making a Roblox Difficulty Chart Obby.

I have made the checkpoint system but when i test it and I die, my body parts have a chance to touch the next checkpoint, if it does then I get that checkpoint and pretty much skip the previous stage.

How do I make it so when the player dies and it’s body parts touches the next checkpoint it doesn’t count it as the player has reached the next stage and the player will be respawned back the to the stage it had died on?

Video of the issue:

Here is my code:

Check if the player is dead before changing their checkpoint

example.Touched:Connect(function(hit) -- hit is a body part

  local humanoid = hit.Parent:FindFirstChild("Humanoid") -- the humanoid has information about the players health
  if not humanoid then return end -- stop checking if there is no humanoid

  if humanoid.Health <= 0 then return end -- stop if the player is dead (0 health)

 --anything past this point will only run for alive players
 --change checkpoint here

end)

I’m kind of a beginner to scripting so what would example be? and where would this code be placed in my code?

Place this where the checkpoint is changed inside of the Touched event

It should say something like part.Touched:Connect(function(hit)

I’m not sure but I think your code doesn’t work because you didn’t put an if-statement to check that the thing that touches the value/checkpoint is Humanoid or not. Which matters because your code doesn’t know what actually touches or needs to touch the part.

I didn’t test to see if its true, its a minor change but it deserves trying.

Like this?:

for i, v in pairs(checkpoints:GetChildren()) do
v.Touched:Connect(function(hit)
local player = Players:GetPlayerFromCharacter(hit.Parent)

	if not player or not player:FindFirstChild("leaderstats") then
		return
			
			v.Touched:Connect(function(hit) -- hit is a body part

				local humanoid = hit.Parent:FindFirstChild("Humanoid") -- the humanoid has information about the players health
				if not humanoid then return end -- stop checking if there is no humanoid

				if humanoid.Health <= 0 then return end -- stop if the player is dead (0 health)

				--anything past this point will only run for alive players
				--change checkpoint here

			end)

How and where do I put it in. I’m not good at scripting but I have no robux to hire one for my game. That’s why I ask. I try to get better though so sorry if my questions sounds bad.

Don’t worry, I am a starter too, as well I don’t have robux to hire someone. If you want, we can work together sometimes.

I can’t show you where to place it because I can’t access the video with your code anymore.