I am trying to testfor if a player fulfills two different criteria. One criteria cannot be changed and is: score_money=5000. I have tried to come up with another criteria to target a very specific player. For example I've tried:

/testfor @p[tag=buyHSR,score_money=5000]

/testfor @p[l=30,score_money=5000]

/testfor @p[score_buy=1,score_money=4500]

The problem, all of these commands work on singleplayer, and not on multiplayer. What happens on multiplayer is that it will testfor the score_money=500 of the nearest player and execute the following commands despite whether or not that same player has the score_buy=1 tag. So, if I am closest to the command blocks and have insufficient money but my friend has enough, who is farther away, the selector will find my friend but execute the commands for me. (This causes my money score to reach into the negatives). In summary, the target selector favors one criteria over the other depending on who has one of the criteria. I am trying to get a selector that will succeed only if both citeria are met.
I am running Minecraft 1.12.2.

  • Interesting, that should just work. Can you try to cleanly reproduce it? Create a new world with commands on, /scoreboard players tag @s add test, /scoreboard players tag @s add abc, say @s[tag=test,tag=abc]. What do you get? May 6, 2018 at 20:57
  • Those should all work. I just tested /testfor @p[score_buy=1,score_money=5000,l=30,tag=buyHSR] and it functions successfully. I am not sure how/who it would target in multiplayer. One more thing to point out, score_money=5000 is going to target players who have a score of 5000 or less. Here is the wiki on selecting targets by score. You said it targets correctly if you remove one of the arguments so I doubt it's a problem but just incase.
    – IronAnvil
    May 6, 2018 at 21:07
  • Also, to note it, generally testfor blocks are not necessary. The testfor commands are being removed in 1.13. If the next step is a conditional chain block which also has a target selector, skip the testfor block and use the target selector next command.
    – IronAnvil
    May 6, 2018 at 21:15
  • I added information in the question.
    – user204836
    May 6, 2018 at 22:08

1 Answer 1


Your target selectors are not favoring one criteria over another.

When you add arguments to the @p target selector variable, it selects the nearest player who meets all the criteria even if there are other players closer who do not. In other words, it does not select only the closest player and test them to see if they meet the criteria.

I recommend using a radius or volume dimensions with or without coordinates in the target selector.

The easiest solution would be to use a radius:

/testfor @p[score_money=5000,r=10]

This will select the nearest player who has a money score of 5000 or less, and is within 10 blocks of the command execution.

Note: This is not testing for a player who has at least 5000, but 5000 or less. This may be why you are going into negative numbers. Anyone with less then 5000 within 10 blocks will satisfy this.

/testfor @p[score_money_min=5000,r=10]

The above will testfor the nearest player who has 5000 or more and is within 10 blocks.

Like I mentioned in the comments, the testfor command is not a good way to do most things. In your case it finds anyone who does meet all the criteria and if it finds any player who does, a conditional block after it will execute. Instead use the above target selector in whatever would be the next command.

Lets say you are selling stone for 5000 money, the commands could be:

give @p[score_money_min=5000,r=10] stone 1
scoreboard players remove @p[score_money_min=5000,r=10] money 5000

Another way you could do it, you could scoreboard tag the nearest player and then test the player with that tag:

scoreboard players tag @p add Nearest
give @a[score_money_min=5000,tag=Nearest] stone 1
scoreboard players remove @a[score_money_min=5000,tag=Nearest] money 5000
scoreboard players tag @a remove Nearest
  • For my situation, the scoreboard tag works the best. I am infact using a buy/sell system. (The reason I used the testfor command is because I have other conditional commands that depend on the testfor. Otherwise I would like you mentioned, use /execute.)
    – user204836
    May 8, 2018 at 0:03

You must log in to answer this question.