Obby checkpoint problem

Hi, I was trying to patch a bug in my game but also made another one, When I test the game in studio, it says I’m on stage 2 instead of stage 1,

here’s proof:
Screenshot 2023-03-19 at 18.47.45

And here’s my code:

local Checkpoints = workspace.Checkpoints

game.Players.PlayerAdded:Connect(function(player)
	local leaderstats = Instance.new("Folder",player)
	leaderstats.Name = "leaderstats"
	local Checkpoint = Instance.new("IntValue",leaderstats)
	Checkpoint.Name = "Stage"
	Checkpoint.Value = 1

	player.CharacterAdded:Connect(function(character)
		wait()
		if Checkpoint.Value > 1 then
			character:MoveTo(Checkpoints:FindFirstChild(Checkpoint.Value - 1).Position)
		end
	end)
end)

for i, V in pairs(Checkpoints:GetChildren()) do
	V.Touched:Connect(function(hit)
		if hit.Parent:FindFirstChild("Humanoid") then
			local character = hit.Parent
			local player = game.Players:GetPlayerFromCharacter(character)
			local Checkpoint = player.leaderstats.Stage
			if tonumber(V.Name) == Checkpoint.Value then
				Checkpoint.Value += 1

			end
		end
	end)
end

can anyone help me?

First, if you want the progress to save also create an .PlayerRemoving function, and save the data.

If you did that and didn’t include it above please reply to me that.

Mind that I meant that if you also use a datastore to save the data.

where do I put that function? because I don’t know where in the script to put it.

Do you save the data too, or this is the whole script?

I didn’t put the save data in, that’s the whole script.

Well then if you want the player to spawn in the corresponding spawn, then first set up a datastore to save data, which shouldn’t be hard as you are only using one value.

Tutorial for DataStores: Data Stores | Roblox Creator Documentation

It may seem hard but you’ll get it sooner or later.

If you won’t get it I’m sure there are many good tutorials on YT on how to make an obby, explaining the steps.