I am trying to do command blocks for a map this kid in my class but have got stuck on a particular part. So what I am trying to do is every 20 game ticks effect them with instant damage then reset the scoreboard counter but only while they are within a 2 block radius of a Armour stand named damage-radius (that is also the scoreboard name) The problem I'm having is when 1 person is within that radius it adds to the scoreboard of all players thank you in advance here is what I have done already these are running in chain command blocks that are always active with command 2 and 4 being conditional also im pretty sure the command is in the 2nd command block

execute @a ~ ~ ~ /testfor @e[name=damage-radius,r=5]

/scoreboard players add @a damage-radius 1

/effect @a[score_damage-radius=20,score_damage-radius_min=20] minecraft:instant_damage 1 1

/scoreboard players set @a[score_damage-radius_min=20] damage-radius 0


Solution 1:

I am going to explain what your commands are actually doing.

execute @a ~ ~ ~ /testfor @e[name=damage-radius,r=5]

This means execute the command testfor @e[name=damage-radius,r=5] from the location of all players. This will result positive if there is an armor stand within 5 block radius of the player and run the next command. It does nothing to target the player. It only returns that there is an armor stand near a player.

/scoreboard players add @a damage-radius 1

This means add 1 to the damage-radius objective for all players. This does not target any specific player. This is your problem.


A better way to do it. First, skip the testfor. Second, run the command directly by targeting the player that is near the armor stand (Backwards of your method of targeting an armor stand that is near a player)

execute @e[name=damage-radius] ~ ~ ~ scoreboard players add @a[r=5] damage-radius 1

This means execute the command scoreboard players add @a[r=5] damage-radius 1 at the location of an entity named "damage-radius."

This will add 1 to the damage-radius objective of only the player that is near the armor stand.

Your other two commands will work as they are.