I need data store checkpoints.

local ds =  game:GetService("DataStoreService")
local ds1 =  ds:GetDataStore("PositionSavingSystem")

game.Players.PlayerAdded:Connect(function(player)
	local val = Instance.new("Vector3Value", player)
	val.Name = "Position"
	
	local userdata
	pcall(function()
		userdata = ds1:GetAsync(player.UserId)
	end)
	
	if userdata then 
		game.Workspace:WaitForChild(player.Name):WaitForChild("HumanoidRootPart").CFrame = CFrame.new(userdata.x, userdata.y, userdata.z)
	else
		ds1:SetAsync(player.UserId, {
		     x = 0,
		     y = 3,
		     z = 0  
		})	
	end
end)

game.Players.PlayerRemoving:Connect(function(player)
	ds1:SetAsync(player.UserId, {
	    x = player.Position.Value.X,
	    y = player.Position.Value.Y,
	    z = player.Position.Value.Z
	})
end)
game.Players.PlayerAdded:Connect(function(player)
	local val = player:WaitForChild("Position")
    player.CharacterAdded:Connect(function(char)
	  while true do 
		    wait(1)
		    val.Value = char:WaitForChild("HumanoidRootPart").Position
	    end
    end)
end)

those are my position savers, but it resets them if they leave dead, and when they die they get sent back to spawn. Help! And, if you could, post the entire script and specify in unclear parts (I'm new to scripting)