Checkpoint System Not Working As Intended

I’ve been working on a commission recently and I ran into a problem:

  • My checkpoint script won’t move the player to the first checkpoint.
  • What am I missing? A simple wait or a repeat wait()?
local checkpoints = game.Workspace:WaitForChild("Checkpoints")
local DS = game:GetService("DataStoreService") 
local Key = DS:GetDataStore("Stages")

game.Players.PlayerAdded:Connect(function(player) 
	local data = Key:GetAsync(player.UserId .. "-CurrentStage")
	
	
	
	local folder = Instance.new("Folder") 
	folder.Name = "leaderstats"
	folder.Parent = player 
	
	local Stage = Instance.new("IntValue")
	Stage.Name = "Stage" 
	Stage.Parent = folder
	Stage.Value =  data or 0
	
	
	local value2 = Instance.new("BoolValue") -- for timing the player, ignore this for now.
	value2.Name = "Started"
	value2.Value = false
	value2.Parent = player
	

	
	
	player.CharacterAdded:Connect(function(char)
		wait()
		local hum = char:WaitForChild("Humanoid")
		char:MoveTo(checkpoints[Stage.Value].Position)
		player.Started.Value = false
		hum.Touched:Connect(function(hit)
			
			if hit.Parent == checkpoints then
				hit.TouchEnded:Connect(function(hit)
					player.Started.Value = true		
				end)
				if tonumber(hit.Name) == Stage.Value + 1 then
					Stage.Value = Stage.Value + 1
					player.Started.Value = false	
				end
			end
		end)	
	end)
end)



game.Players.PlayerRemoving:Connect(function(player) 
	Key:SetAsync(player.UserId .. "-CurrentStage", player.leaderstats.Stage.Value)
end)




1 Like

You can use : .HumanoidRootPart for moving.
For example :

char.HumanoidRootPart.CFrame = CFrame.new(checkpoints[Stage.Value].Position*)

“*” : You can use the Position Value for this as well.

1 Like

Hey, thank you for the reply, I found what was wrong after a bit of messing around.

I ended up having to check if the player was on the first stage, and if they are, start their timer which fixed it and I don’t know why. :+1: