Minecraft – How to use testfor to testfor players nearby

minecraft-commandsminecraft-java-edition

I want to use a command block to testfor a player within three blocks of it. It should then activate a comparator. I followed the basic syntax, typing testfor @a [r=3]. However, when I ran it, it said that that was the wrong way to syntax it. I followed its tips, and got testfor @a {r:3} but then no matter what I tried, the comparator wouldn't turn on. Frustrated, I typed /testfor in the chat to see the proper syntax. It said testfor <player> [datatag] but when I used that syntax earlier, it gave me a syntax error! I went back and forth between them, and nothing worked.

Best Answer

You have a space in the selector.

testfor @a[r=3]

No space between @a and [r=3].

Just to note it, the comparator output signal strength will be equal to the amount of players it finds in that radius.