For loop not running to the last value

Hey, I’m creating a line game, and I’m having an issue with my client move handler.

	if PlayerIndex > NewIndex then
		for i = PlayerIndex, NewIndex, -1 do
			print(i)
			if i == 0 then continue end
			local Pad = Numbers:FindFirstChild(i)
			
			Humanoid:MoveTo(Pad.Position)
			Humanoid.MoveToFinished:Wait()
		end
	else
		print("plr index is not greater than new index")
		print(NewIndex)
		print(PlayerIndex)
		for i = PlayerIndex, NewIndex, 1 do
			print(i)
			if i == 0 then continue end
			local Pad = Numbers:FindFirstChild(i)
			
			Humanoid:MoveTo(Pad.Position)
			Humanoid.MoveToFinished:Wait()
			
			print("Move to finished.")
		end
	end

NewIndex prints: 2
PlayerIndex prints: 1
“plr index is not greater than new index” also prints

Theoretically, since playerIndex is 1, and NewIndex is 2, the print(I) line should print 1 and 2, correct?

Error: it only prints 1, not 2.

This is how lua for loops work.

image

It started at 1, and printed it and then incremented it. The reason it didn’t print 2 is because it didn’t reach that point in the code in the first place. Once it becomes 2 the loop ends. You should increase new index by 1 when starting the loop to fix this.