local S="\083\116\097\103\101"local e=true local z={}local l=1 while true do local S=Workspace:FindFirstChild("\067\104\101\099\107\112\111\105\110\116 "..l,true)if not S then print("\076\097\115\116 \067\104\101\099\107\112\111\105\110\116 \058 "..l-1)break end table.insert(z,S)l=l+1 end game.Players.PlayerAdded:connect(function(e)local l=e:FindFirstChild("\108\101\097\100\101\114\115\116\097\116\115")or Instance.new("\077\111\100\101\108",e)l.Name="\108\101\097\100\101\114\115\116\097\116\115"local E=Instance.new("\073\110\116\086\097\108\117\101",l)E.Name=S E.Value=1 e.CharacterAdded:connect(function(S)local e=z[E.Value]if e then repeat wait()until S.Parent S:MoveTo(e.Position)else warn("\067\104\101\099\107\112\111\105\110\116 "..(E.Value.." \110\111\116 \102\111\117\110\100"))end end)end)for z,l in ipairs(z)do l.Touched:connect(function(l)local E=game.Players:GetPlayerFromCharacter(l.Parent)if not E then return end local s=l.Parent:FindFirstChild("\072\117\109\097\110\111\105\100")if not s or s.Health<=0 then return end local B=E:FindFirstChild("\108\101\097\100\101\114\115\116\097\116\115")if not B then return end local f=B:FindFirstChild(S)if not B then return end if e and f.Value+1==z or not e and f.Value<z then f.Value=z end end)end

local STAT_NAME = "Stage"
local PREVENT_SKIPPING = true

local checkpoints = {}

local i = 1
while true do
	local checkpoint = Workspace:FindFirstChild("Checkpoint " .. i, true)
	if not checkpoint then print("Last Checkpoint : " .. i-1) break end
	table.insert(checkpoints, checkpoint)
	i = i + 1
end

game.Players.PlayerAdded:connect(function(player)
	local leaderstats = player:FindFirstChild("leaderstats") or Instance.new("Model", player)
	leaderstats.Name = "leaderstats"
	
	local checkpointStat = Instance.new("IntValue", leaderstats)
	checkpointStat.Name = STAT_NAME
	checkpointStat.Value = 1
	
	player.CharacterAdded:connect(function(character)
		local goto = checkpoints[checkpointStat.Value]
		if goto then
			repeat wait() until character.Parent
			character:MoveTo(goto.Position)
		else
			warn("Checkpoint " .. checkpointStat.Value .. " not found")
		end
	end)
end)

for index, checkpoint in ipairs(checkpoints) do
	checkpoint.Touched:connect(function(hit)
		local player = game.Players:GetPlayerFromCharacter(hit.Parent)
		if not player then return end
		local humanoid = hit.Parent:FindFirstChild("Humanoid")
		if not humanoid or humanoid.Health <= 0 then return end
		local leaderstats = player:FindFirstChild("leaderstats")
		if not leaderstats then return end
		local checkpointStat = leaderstats:FindFirstChild(STAT_NAME)
		if not leaderstats then return end
		
		if (PREVENT_SKIPPING and checkpointStat.Value + 1 == index) or (not PREVENT_SKIPPING and checkpointStat.Value < index) then
			checkpointStat.Value = index
		end
	end)
end
