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?

2 Answers 2

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .