How would you tellraw a player on low health?

I am trying to create a mechanic that displays a "(Player)'s life is in danger!" When low on health. This is my main command:

 tellraw @a[scores={hp2=1..1},gamemode=survival] {"text":"","color":"red","extra":[{"selector":"@p"},{"text":"'s life is in danger!"}]}

However, because the player fits the criteria (and continues to), the command just spams the chat.


You can use tags for this. Tag the player and add tag=!someTag to your selector to stop the command from executing. The setup should look like this:

(Repeating command block)

/tellraw @a[tag=!someTag,scores={hp2=1},gamemode=survival] {"text":"","color":"red","extra":[{"selector":"@p"},{"text":"'s life is in danger!"}]}

(Chain command block)

/tag @a[tag=!someTag,scores={hp2=1},gamemode=survival] add someTag

(Chain command block)

/tag @a[tag=someTag,scores={hp2=2..}] remove someTag

Not sure why you are using 1..1 as that can only be 1. I changed the values so the text is displayed if hp2 is 1 and the tag will be removed when hp2 is 2 or more.