Checkpoints not working

Hey, this is my first post. I have a checkpoint/leaderstats script for my obby. The leaderstats work, however the checkpoints do not work and the update for the leaderstats doesn’t work, its stuck on 1. Can someone please help me?

local checkpoints = workspace:WaitForChild("Checkpoints")

game.Players.PlayerAdded:Connect(function(plr)

local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = plr


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

plr.CharacterAdded:Connect(function(char)
	local hum = char:WaitForChild("Humanoid")
	wait()
	char:MoveTo(checkpoints[v.Value].Posistion)
	
	hum.Touched:Connect(function(hit)
		if hit .Parent == checkpoints then
			if tonumber(hit.Name) == v.Value +1 then
				v.Value = v.Value +1
			end
		end
	end)
end)

end)

1 Like

I believe hit is getting the player body part that touched the checkpoint, and not the checkpoint itself. This is probably stopping the script from running, as the player is not a member of checkpoints.

What would I use instead of hit?

You’re attempting to check if hit.Parent is equal to the checkpoints variable, and not a valid player? Try this:

	hum.Touched:Connect(function(hit)
		if hit:IsA("SpawnLocation") then
			if tonumber(hit.Name) == v.Value +1 then
				v.Value = v.Value +1
			end
		end
	end)

You could add SpawnPoint references to check if the humanoid has hit a SpawnLocation object, then add the value

I believe hit is fine. It’s this line that’s stopping it from running, at least I think.

		if hit .Parent == checkpoints then

To test this, try marking it as a comment. Also to test some more, put print(hit.Name) to see what it is.

I tried to run the script, didn’t work.

Could you try adding print() statements to see where the error could lie?

Try changing this to HumanoidRootPart

I solved my issue. Thanks for all your guys help!