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.
Best Answer
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.
Pictures about "How would you tellraw a player on low health?"



How do you give a player more health in Minecraft?
How to Enter the CommandHow do you do a Tellraw?
To damage a player, set that player's damage scoreboard to how much damage you want to apply(negatives heal players), then run the function editor:deal_damage as the player you want to damage and you are done.Why Sudo Is The Best Command in Minecraft
Sources: Stack Exchange - This article follows the attribution requirements of Stack Exchange and is licensed under CC BY-SA 3.0.
Images: Andrea Piacquadio, Ali Pazani, Isabella Mendes, Ketut Subiyanto
