1

I am trying to testfor @a health at 0 (when the player dies) using the /scoreboard command. The commands I was using do not seem to be working; the commandblock output is "cannot be found." I added an objective:

/scoreboard objectives add health health

And I added the testfor:

/testfor @p[score_health_min=0,score_health=0]

Yet this is brings up the error:

Entity '@p[score_health_min=0,score_health=0]' cannot be found.

How can this be done correctly?

closed as unclear what you're asking by Fabian Röling, Timmy Jim, Studoku, Lore Friendly, Riley Feb 5 '18 at 7:02

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • This works for me. When are you executing the command? Do you execute anything conditionally from it? Are you using it in a repeating command block? If you do, then you will always see the current state in the output, which is usually an error, except if it finds something, which is exactly one tick when you respawn. – Fabian Röling Feb 4 '18 at 14:14
  • I'm voting to put this on hold for now, because exactly what you described works for me. You need to give more details. – Fabian Röling Feb 4 '18 at 14:15
0

I am guessing you have this in a repeating command block. When run this way, if there are currently no dead players, the "error" the command block will output is:

Entity '@p[score_health_min=0,score_health=0]' cannot be found

This is functioning properly. Your commands work properly as is, there is nothing wrong with them. The only time this output would be different is if you were to click on the command block while there was a dead player who had not respawned.


I have a few suggestions though:

  • Unless you are doing something very specific needing to target only the closest player, use @a instead of @p as this will make it multiplayer capable.
  • As you are testing for a number at or below 0, you do not need to use the minimum argument.
  • The testfor command is not all that useful, you can use the target selector in a command that actually does something useful instead.

An example command with the suggested target selector to make the dead player say hello:

execute @a[score_health=0] ~ ~ ~ say Hello

Note: This will repeat until the dead player respawns so chat would be filled will a player saying hello.

This can be overcome by having a conditional chain command block with command:

scoreboard players reset @a health

Another way of doing it, use the deathCount criteria. This will allow you to test for a minimum score of 1.

Command to create the objective:

/scoreboard objectives add Deaths deathCount

Then two command blocks. The first a Repeat Unconditional Always Active with command:

execute @a[score_Deaths_min=1] ~ ~ ~ say hello

The second a Chain Conditional Always Active with command:

scoreboard players reset @a Deaths
2

While the above answer is valid, I believe this would be faster and more efficient.

scoreboard objectives add dieTime stat.timeSinceDeath
execute @a[score_dieTime=0] ~ ~ ~ say I am dead!
  • This faces the same problem of spamming the chat. The objective is set to 0 when the player dies and stays at 0 until the player clicks the respawn button. – IronAnvil Feb 5 '18 at 5:27