2

I have an /execute command in a repeating command block, such as:

execute @a ~ ~ ~ say hi

This makes every player say hi every tick, even if they are dead and at the 'Respawn?' screen.
How would I make the /execute only happen if the player is alive?

6

This can be done with the health scoreboard. Create an objective with:

/scoreboard objectives create h health

This creates an objective h, which tracks player's health (by number of half-hearts).
Change your command to:

execute @a[score_h_min=1] ~ ~ ~ say hi

This only triggers if the player has at least a half-heart (they're alive).

2

You can use a selector that does not have the ability to target dead players, such as @e (with type=Player to ensure player-based targeting):

/execute @e[type=Player] ~ ~ ~ say hi

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.