Parkour Checkpoint problem

I was making a parkour for a while, my parkour is almost finished but there is a problem. Like if my character dies and my characters leg or arm… touch any old checkpoints when falling it respawn me on that checkpoint how to prevent that?

-- local Players = game:GetService("Players")
local ServerStorage = game:GetService("ServerStorage")

local checkpoint = script.Parent

function onTouched(hit)
	if hit and hit.Parent and hit.Parent:FindFirstChildOfClass("Humanoid") then
		local player = Players:GetPlayerFromCharacter(hit.Parent)
		local checkpointData = ServerStorage:FindFirstChild("CheckpointData")
		if not checkpointData then
			checkpointData = Instance.new("Folder")
			checkpointData.Name = "CheckpointData"
			checkpointData.Parent = ServerStorage
		end
		
		local userIdString = tostring(player.UserId)
		local checkpointValue = checkpointData:FindFirstChild(userIdString)
		if not checkpointValue then
			checkpointValue = Instance.new("ObjectValue")
			checkpointValue.Name = userIdString
			checkpointValue.Parent = checkpointData
			
			player.CharacterAdded:connect(function(character)
				wait()
				local storedCheckpoint = ServerStorage.CheckpointData[userIdString].Value
				character:MoveTo(storedCheckpoint.Position + Vector3.new(math.random(-4, 4), 4, math.random(-4, 4)))
			end)
		end
		
		checkpointValue.Value = checkpoint
	end
end

checkpoint.Touched:Connect(onTouched)

When you find the humanoid, check whether its humanoid:GetState() is equal to Enum.HumanoidStateType.Dead. If it is, you return and the code doesn’t execute further.

Also I’ve noticed that you mentioned that the problem was with touching an old checkpoint. Simply check whether checkpoint == checkpointValue.Value+1 and if so, assign the new checkpoint value - this will also prevent players skipping checkpoints.


So that should look like this

if checkpoint == checkpointValue.Value+1 then
    checkpointValue.Value = checkpoint
end