Minecraft – How to display stats like death count using titles

minecraft-commandsminecraft-java-edition

I'm making a dungeon-crawler adventure map, and at the end I would like the system to tell the player, either within the chat or on screen (using /title) these criteria:

  • Number of deaths
  • Number of rooms entered (out of X)
  • Number of mobs killed
  • Number of times fell in lava/from a high place

Things like that. I know that there's a way so that the player can press tab or have it displayed on the right of the screen, but I would like it so it's kind of a credits thing.

Best Answer

As you already have the objectives set up and working, it's fairly simple to output them. You'll need to use the JSON format to get the player's score, like this:

["",{"score":{"name":"*","objective":"ObjectiveName"}}]

Where ObjectiveName is the name of the objective you want to get the player's value of.

/title already accepts JSON data, so all you need to do is:

/title @p title ["",{"score":{"name":"*","objective":"ObjectiveName"}}]

/say doesn't accept the JSON format, so you should use /tellraw instead, which does:

/tellraw @p ["",{"score":{"name":"*","objective":"ObjectiveName"}}]

If you want it as part of a sentence, you could change the JSON part to something like:

["You have died ",{"score":{"name":"*","objective":"ObjectiveName"}}, " times."]