Basically, I'm trying to make a hunger games world in minecraft but I'm not sure how I can send all players back to spawn when the player wins.

  • 1
    Well if it's on the same server then a tp all command should work. – Robbie Aug 2 '19 at 23:50
  • yea but i want to make it to tp everyone when theres only 1 person left – oopsiedoopsie Aug 3 '19 at 0:27

First, have a look at this post to learn more about commands. Your problem is that you need to tp all players to a location when there's one player left in the arena. So the steps you need to accomplish are:

1) Count the players
2) Store the amount of players
3) When that number is 1 (there is one player left in the arena) teleport all players to some location.

  1. To do this, first set up a scoreboard to count the players in the arena:
    scoreboard objectives add numPlayers dummy.

  2. Then, at the center of the arena run execute store result score number numPlayers run execute if entity @a[distance=..x] every tick, where number is a fakeplayer and x is the distance from the center of the arena to the edges. This will constantly store the amount of players in the arena to the scoreboard.**

  3. Now, if there is a 1 stored in the scoreboard (indicating one player left), you need to tp the players, so run execute if score number numPlayers matches 1 run tp @a x y z. This will teleport all players to the coordinates x, y, and z if there is one player left in the arena. Remember that number is a fake player we created to store the value, and their value is in the objective numPlayers.

**The way the storing works is that the execute store result command basically takes a value produced by the command after the run keyword and puts it in the latter half of the execute store result command, which in this case in number's score in the objective numPlayers. The part after the run, execute if entity @a[distance=..x], returns the amount of players because the if entity subcommand has two functions: running some command after the if if the condition is true, or returning the amount of entities that passed the test to what is before the preceding run keyword if there is no run keyword coming afterwards.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.