Minecraft – way to find out a player’s name using commands

minecraft-commandsminecraft-java-edition

I'm trying to make map where if you die, it says in the chat that the player in question has died. For example, if a guy named BlehBlehBleh died, it would say in the chat, "BlehBlehBleh has died!" or something like that.
P.S I think it has something to do with scoreboards.

Best Answer

Using selectors, you can easily say BlehBlehBleh died! With the say command

/say @a[deaths=1] has died! That will say any player with the score deaths = 1 has died. Then you would set his deaths to 0 to avoid a loop :) Also, detect IF a player has died first before doing the command. So order of the commands:

scoreboard players test @a deaths 1

Then

say @a[deaths=1] has died!

scoreboard players set @a[deaths=1] deaths 0

So you would be right thinking its about scoreboards.

Edit: To store someones name in a scoreboard just make an objective then type this in

scoreboard players set @a objectiveName 0 That would make the score of every player set to 0. To add a deathcount just do scoreboard objectives set deaths deathCount I believe