CheckPoint Does not work

Hello, Im trying to make a checkpoint for a obby.
No errors in the output and it does not work.
Here is my script:

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

If it will work efficient like this :

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.Parent = leaderstats
	
	player.CharacterAdded:Connect(function(char)
		local hum = char:WaitForChild("Humanoid")
		repeat wait() until hum
		char:PivotTo(checkpoints:WaitForChild(tostring(stage.Value)).CFrame)
		
		hum.Touched:Connect(function(hit)
			if hit.Parent == checkpoints then
				stage.Value = tonumber(hit.Name)
			end
		end)
	end)
end)
1 Like

Now when i load in you automaticly teleport to that checkpoint.

1 Like

Can you explain more the problem, what do you expect ?

Alright, i have a obby, and theres a spawn, and checkpoint, i think your script makes it that the spawnpoint does not exist and instantly overrights the checkpoint as a spawn causing the player to spawn there. cus when i load in i dont spawn at the spawn. and when i touch a other checkpoint and die i dont respawn back there

1 Like

When you die at a checkpoint you go back to the start ?
Can I see how your folder of checkpoints is set ?

1 Like

Try this :

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.Parent = leaderstats
	
	player.CharacterAdded:Connect(function(char)
		local hum = char:WaitForChild("Humanoid")
		repeat wait() until hum
		char:PivotTo(checkpoints:WaitForChild(tostring(stage.Value)).CFrame)
		
		hum.Touched:Connect(function(hit)
			if hit.Parent == checkpoints then
				stage.Value = tonumber(hit.Name)
			end
		end)
	end)
end)
2 Likes

Thanks, It works perfectly! question tho. does this script work for more checkpoints?

1 Like

Yes, I think you’ve just made some mistakes but there was an important one, you mispelled the folder when you set the variable checkpoints :
You :

local checkpoints = workspace:WaitForChild("CheckPoints")

Me :

local checkpoints = workspace:WaitForChild("Checkpoints")

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