Checkpoint system starts at 1 in studio, but 0 in-game

Hello I have a leaderstats obby checkpoint system in my game. The leaderstats will automatically set your “Stage” value to 1 upon joining for the first time. This works in studio, but when I play the game, it sets it to 0, which breaks the game. Can anyone help?

I don’t think anyone can help if you don’t post the code you are using.

1 Like
local checkpoints = workspace:WaitForChild("Checkpoints")

game.Players.PlayerAdded:Connect(function(player)
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = player

	local stage = Instance.new("IntValue")
	stage.Name = "Stage"
	stage.Value = 1
	stage.Parent = leaderstats

	player.CharacterAdded:Connect(function(char)
		local hum = char:WaitForChild("Humanoid")
		wait()
		char:MoveTo(checkpoints[stage.Value].Position)

		hum.Touched:Connect(function(hit)
			if hit.Parent == checkpoints then
				if tonumber(hit.Name) == stage.Value + 1 then
					stage.Value = stage.Value + 1
				end
			end
		end)
	end)
end)

Try putting this as the first line of your CharacterAdded:Connect function:

repeat task.wait() until char.Parent
1 Like

Does your data save?

If it does, then it might be loading saved data that starts at 0

1 Like