Agreed, do what Rael says. have 2 alterable values for each player, 1 for laps, and 1 for distance.
The First variable we will name "Laps", now, every time a player crosses over the loop line, you add 1 to the value. Now here is where the Second variable, " Distance " comes in, we take the position of the checkpoint/start line, and compare the distance between the player and it, the largest number will be the one in first, the least highest second, and so on. the laps is also relative to distance, so:
If I were on lap 2, but were 45 pixels past the checkpoint, it would still be considered higher than lap 1, being 3000 pixels away from the checkpoint, even if it were extremely close to the checkpoint.
Man I wish I had the enthusiasm to fangame again
EDIT: 8 Direction overhead? use checkpoints, thats pretty much the only thing I can think of thatll fix it up lickety split