Is there a way to teleport someone somewhere after they have died (x) amount of times? [closed]

Solution 1:

If this is for the Legacy Console Edition, I don't think this is possible as scoreboards aren't available.

However, if this is for the Java Edition this is easily done with the deathCount scoreboard criterion.

Step 1: Create scoreboard objective

Run this command:

scoreboard objectives add deaths deathCount

This adds a scoreboard objective called "deaths" that increments when a player dies.

Step 2: Teleport players when they die 3 times

Add this command to a repeating, unconditional, always active command block:

execute as @a[scores={deaths=3}] run tp @s X Y Z

where X, Y, and Z are the coordinates you want to teleport the people who've died to. This would continually run the command tp @s X Y Z as all the players who have their deaths objective set to 3.

Step 3: Stop teleporting the players once they've been teleported

The above repeating command block would also mean that players are continually being teleported, meaning that they cannot move. There are two ways I can think of right now, which will only work if the area where you're teleporting the players to can't be accessed by the players who haven't died 3 times (sorry, I don't play on Java and I don't know that many commands).

Method 1: Reset the death counter

Add this command to a repeating, unconditional, always active command block:

execute @a[x=X,y=Y,z=Z,dx=1,dy=2,dz=1] run scoreboard players set @a[scores={deaths=3}] deaths 0

This will set the deaths of all players at X, Y, Z to 0.

Method 2: Use tags

This is if you don't want to reset the counter.

Add the following command to yet another repeating, unconditional, always active command block:

execute as @a[scores={deaths=3}] run add tag needsToBeTeleported

This will add the tag needsToBeTeleported (or whatever you want to call it) to all players who have died 3 times.

Then, go back to the commmand block in step 2 and change it to this:

execute as @a[tag=needsToBeTeleported] run tp @s X Y Z

This will teleport all players with the tag needsToBeTeleported to X, Y, Z.

Finally, add another repeating, unconditional, always active command block with the command:

execute @a[x=X,y=Y,z=Z,dx=1,dy=2,dz=1] run tag @s remove needsToBeTeleported

This would remove the tag needsToBeTeleported from all players at X, Y, Z.


Also, make sure that all the repeating command blocks are in a loaded chunk by placing them in the spawn chunk, using the forceload command, or by simply placing them in an area you know someone is going to be in all the time.

If you don't want command block stuff in chat like Teleported <player> to <x>, <y>, <z> you can run gamerule commandBlockOutput false.


Disclaimer: I only play BE so I actually haven't tested any of this out, but it should work.