SpookySkeleton
Give the tail pieces a private variable called "index".
Then every time you create a tail piece set their index to -1. Finally to do the ordering use a "for each ordered" loop:
For each tail ordered by tail.value('index') ascending
--- tail: set index to loopindex
That will make the tail piece right behind the player always be 1 counting up to the oldest one. This loop also cleanly handles destroying pieces, so they will be recalculated correctly.