Touching a checkpoint will respawn you somewhere else than the checkpoint that you touched

Hey devs, I got an idea for one of my game but had no ideas on how to do it so I searched for a long time and I found nothing.

So my idea was to when you touch a part, you’ll unlock a new checkpoint but that is not the part that you touched. Like if you touch a part in coordinates 0, 0, 0 and that you will respawn at coordinated 10, 0, 0. Can anyone help me?

Here is my script :

local spawn = script.Parent
spawn.Touched:connect(function(hit)
	if hit and hit.Parent and hit.Parent:FindFirstChild("Humanoid") then
		local player = game.Players:GetPlayerFromCharacter(hit.Parent)
		local checkpointData = game.ServerStorage:FindFirstChild("CheckpointData")
		if not checkpointData then
			checkpointData = Instance.new("Model", game.ServerStorage)
			checkpointData.Name = "CheckpointData"
		end
		
		local checkpoint = checkpointData:FindFirstChild(tostring(player.userId))
		if not checkpoint then
			checkpoint = Instance.new("ObjectValue", checkpointData)
			checkpoint.Name = tostring(player.userId)
			
			player.CharacterAdded:connect(function(character)
				wait()
				character:WaitForChild("HumanoidRootPart").CFrame = game.ServerStorage.CheckpointData[tostring(player.userId)].Value.CFrame + Vector3.new(0, 4, 0)
			end)
		end
		
		checkpoint.Value = spawn
	end
end)

There is an article about this on the Developer Hub.

https://developer.roblox.com/en-us/api-reference/property/Player/RespawnLocation