How do I send all players back to lobby
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.
Solution 1:
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.
To do this, first set up a scoreboard to count the players in the arena:
scoreboard objectives add numPlayers dummy
.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.**Now, if there is a 1 stored in the scoreboard (indicating one player left), you need to
tp
the players, so runexecute if score number numPlayers matches 1 run tp @a x y z
. This will teleport all players to the coordinatesx
,y
, andz
if there is one player left in the arena. Remember thatnumber
is a fake player we created to store the value, and their value is in the objectivenumPlayers
.
**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.