Minecraft Java Edition – How to Teleport Someone with Specific Death Count Scoreboard in 1.16

minecraft-commandsminecraft-java-edition

My friends and I are playing a Hardcore style playthrough of Minecraft. We want instead of death being permanent, teleport the player to a challenge area that gets harder the more you die. The commands I've tried already haven't seemed to work.

Best Answer

Because Minecraft commands have no event system, you cannot just say: 'run when someone dies'. Instead, you need to keep track of a separate deathCount variable that constantly get set back to zero. The purpose of this is to detect when a player dies. If they die, their score goes up by one, your commands run, then it goes back to zero. If they don't die, nothing happens. Therefore, you use this temporary variable to detect when they die, because if they are to die, their score goes up by one for one, and only one iteration of a command block chain.

To summarize, you keep track of two deathCount variables. One is the normal one, to tell you how many times they have died in total, so you know which platform to teleport them to. The other is a Temp variable, which serves only to tell you when they die, so you are not constantly teleporting them to a specific spot, but only when and if they die.

Setup

scoreboard objectives add totalDeaths deathCount {"text":"Number of Times Died"}
scoreboard objectives add tempDeaths deathCount

An example loop

execute as @e[scores={totalDeaths=..0,tempDeaths=1}] in minecraft:the_overworld run tp @s 0 64 0   #If they die without dying, they spawn at spawn
execute as @e[scores={totalDeaths=1,tempDeaths=1}] in minecraft:the_nether run tp @s 64 64 64      #Where I assume your first platform are. You can also add datapack dimensions here
execute as @e[scores={totalDeaths=2,tempDeaths=1}] in minecraft:the_nether run tp @s 64 64 -64     #The second platform? All of these are subject to change, this is an example
...                                          # However many more platforms you want

scoreboard players set @a tempDeaths 0       # So that once they die, they do not then constantly get teleported back to that one spot on the platform. If you mess up and create a teleporting loop, there are lots of great answers on Arqade to get you out of it