How can I make this checkpoint system work in multiplayer? Minecraft 1.9

I have a checkpoint system in Minecraft 1.9 that detects a when a player is standing on a certain block, and then summons an armorstand where they are. If they step on a different kind of block, it teleports the player back to the armorstand. The problem is that this only works in single player. If there are 2 players, they will both keep setting checkpoints for each other, and it will become chaotic pretty fast. How can I make this work in multiplayer? PS: I have already tried naming armorstands after players, but you can't put selectors in the customname tag. I tried using scoreboards also, but I'm not so clear on how to use them, so I'm not sure if I'm going about it in the right way.


Solution 1:

At the beginning, in order:

/scoreboard objectives add id dummy

/scoreboard players set @r[score_id=0] id 1

/scoreboard players set @r[score_id=0] id 2

/scoreboard players set @r[score_id=0] id 3

... 

On checkpoint reached:

/execute @p[score_id=1,score_id_min=1] ~ ~ ~ detect ~ ~-1 ~ minecraft:diamond_ore 0 summon ArmorStand ~ ~ ~ {customName:'1'}

/kill @e[type=ArmorStand,name:'1',rm=3]

(repeat for all players, replacing all the 1's except the middle '~-1' with the player's id)

On fail:

/execute @p[score_id=1,score_id_min=1] ~ ~ ~ detect ~ ~-1 ~ minecraft:lit_redstone_ore 0 tp @p @e[type=ArmorStand,name='1'

(repeat for all players, replacing all the 1's except the right middle '~-1' with the player's id)