Checkpoint script

printing in devconsole “Last Checkpoint 55” but we have 75 stages, and it has a arrow that goes to the next checkpoint whenever you reach one to guide you. It completely stops at 55 and won’t go any further

local STAT_NAME = "Stage"
local PREVENT_SKIPPING = true

local checkpoints = {"75"}

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
1 Like

Check to make sure your checkpoints are named correctly. Juding by your script, they should all be named "Checkpoint " followed by the checkpoint number.

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.