Won't teleport after death

Hi,

I am making a system where the player gets teleported to their checkpoint after dying. However, it just simply does not teleport, and I have no idea why. No errors in the output.

game.Players.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function(char)
		local checkpointValue = plr.Character:FindFirstChild("CheckpointValue")
		
		plr.Character:WaitForChild("Humanoid").Died:connect(function()
			local checkpoints = workspace:GetDescendants()
			local hrp = char:FindFirstChild("HumanoidRootPart")
			for i, v in ipairs(workspace:GetDescendants()) do
				if v:FindFirstChild("Decal") then
					if v:FindFirstChild("Decal").Texture == "rbxasset://textures/SpawnLocation.png" then
						if v:FindFirstChild("CheckpointValue").Value == checkpointValue then
							if hrp then
								repeat
									hrp.CFrame = v.CFrame + Vector3.new(0, 2, 0) -- Teleport 2 studs above the checkpoint
								until hrp.CFrame == v.CFrame + Vector3.new(0, 2, 0)
								print("Teleported upon death team for player " .. plr.Name .. ": " .. v.Name)
							else
								warn("HumanoidRootPart not found for " .. plr.Name)
							end
						end
					end
				end
			end
		end)
	end)
end)

I normally don’t spoonfeed but i am extremely bored, could you test this?

game.Players.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function(newChar)
		local checkpoints = workspace:GetDescendants()
		local hrp = newChar.PrimaryPart
		for i, v in ipairs(workspace:GetDescendants()) do
			if v:FindFirstChild("Decal") and
			  v:FindFirstChild("Decal").Texture == "rbxasset://textures/SpawnLocation.png" and
			  v:FindFirstChild("CheckpointValue").Value == checkpointValue and
			  hrp
			then
				hrp.CFrame = v.CFrame + Vector3.new(0,2,0)
				print("Teleported upon death team for player " .. plr.Name .. ": " .. v.Name)
				return
			else
				warn("HumanoidRootPart not found for " .. plr.Name)
			end
		end
	end)
end)

Simply wait for the character to respawn, then teleport to the position!
(make sure the checkpoint system is working)

game.Players.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function(char)
		local checkpointValue = plr.Character:FindFirstChild("CheckpointValue")
		
		plr.Character:WaitForChild("Humanoid").Died:connect(function()
			local checkpoints = workspace:GetDescendants()
			local hrp = char:FindFirstChild("HumanoidRootPart")
			for i, v in ipairs(workspace:GetDescendants()) do
				if v:FindFirstChild("Decal") then
					if v:FindFirstChild("Decal").Texture == "rbxasset://textures/SpawnLocation.png" then
						if v:FindFirstChild("CheckpointValue").Value == checkpointValue then
							if hrp then
                                repeat 
                                    wait(0.2)
                                until hrp.Parent.Humanoid.Health > -5
                                warn('Player could be teleported!')
								repeat
									hrp.CFrame = v.CFrame + Vector3.new(0, 2, 0) -- Teleport 2 studs above the checkpoint
								until hrp.CFrame == v.CFrame + Vector3.new(0, 2, 0)
								print("Teleported upon death team for player " .. plr.Name .. ": " .. v.Name)
							else
								warn("HumanoidRootPart not found for " .. plr.Name)
							end
						end
					end
				end
			end
		end)
	end)
end)

The way I went about this is making each checkpoint a SpawnLocation and turning off CharacterAutoLoads in the Players service. When the player touches a checkpoint, their RespawnLocation property is set to that spawn. That way, you don’t have to deal with teleporting them. I manually respawn the player using LoadCharacter() after setting the RespawnLocation.

However, you have to do a magnitude check and teleport them back in case the respawning doesn’t work.