Minecraft | Selecting the oldest target / one with the least score

minecraft-commandsminecraft-java-edition

On reddit, I saw this and decided to try and recreate it. It mostly went well, except there are still some issues with the selectors.

Right now, I am spawning armor stands relative to the player's location to save the player's position and adding 1 to their timeSaveTBT score every redstone tick. To make it so the player gets teleported back three seconds in time specifically, the armor stands are killed once the score reaches 30. When the player right clicks a fishing rod, the armor stands stop spawning and the player gets teleported to @e[type=armor_stand,name=tracker,c=1] (the c=1 is the important part).

The c=1 works in certain situations, but it doesn't work all the time. I need a relible way to select either the oldest armor stand with the name ptracker or the armor stand with the smallest timeSaveTBT score.

Best Answer

After a lot of thought, i think i know how, if it's a custom command creation then I can't help, but if it's a map, you could create a machine that every 20 ticks(1 second) it powers a command block that will summon an invisible armour stand at your location but 500 blocks above(to allow you to place and break blocks) with the name(not visible) of AS1, then 20 ticks later AS2, then another 20 ticks later AS3,20 ticks after that it will power a command block that will kill all the armour stands named AS1, AS2 and AS3 and restart the machine, when you activate the fishing rod it will tp you 500 blocks below AS3(if it can), then 500 blocks below AS2(If it can) then 500 blocks below AS1. That will make it so when you activate it it will teleport you back 3 seconds.
EDIT: The armour stands have to have no AI so that they will float in the air if you jump when it activates