I am setting up a server spawn, but I need the players to join a discord server before they play, so i am trying to make a radius around the spawn that they cannot leave unless they get teleported out by a mod/admin. I would also want to be able to create multiple of these radii. Any ideas on how to do this?

  • 3
    Flagging as unclear because the question lacks an edition tag.
    – pppery
    Jan 21 '20 at 20:17

You have a few ways to solve this, just decide which one fits you best.

This is the most obvious solution to your problem

Put the commands into a repeating command block for them to work propperly

To prevent players at spawn to move at all:

execute positioned <spawn coordinates> run tp @a[distance=..1] ~ ~ ~

To give them a little space to move:

execute positioned <spawn coordinates> run tp @a[distance=3..5] ~ ~ ~

To give them an area to explore, but still restricted:

execute positioned <spawn coordinates> run tp @a[distance=50..52] ~ ~ ~

You can just change the distance parameter to fit your needs.

You could also do a tag based solution

To give them a little space to move:

execute positioned <spawn coordinates> run tp @a[distance=3..,tag=!canLeaveSpawn] ~ ~ ~

Use this command to allow a player to leave spawn if you set it up with this solution:

/tag <player> add canLeaveSpawn

Or a solution based on barrier blocks

Just set up a wall of barrier blocks, you can give yourself a barrier block with this command, no command block is required for this:

/give @s minecraft:barrier


It may be possible to escape if you can go really fast, but this is about as close as you can get to an invisible wall without using barrier blocks:

/execute positioned <spawn coordinates> as @a[distance=3..6] facing entity @s feet run tp @s ^ ^ ^3

If players can escape, increase the 6 in this command, if you want a bigger area, increase the 3 in the target selector and at the end (both should get the same value)

  • I have been working with commands a lot lately, I guess the first solution is maybe not "the most obvious" solution to everyone
    – user232393
    Jun 9 '19 at 10:12
  • Thank you, this works amazing. Though I am curious as to if it is possible to make it act like a barrier that you cannot pass, not as a "teleport if past said radius".
    – Lithium
    Jun 9 '19 at 16:52
  • I dont think that there is a way to do that (except for actually using barrier blocks). There would be a way if they only can escape in one direction, so if it is not a circular radius, but an invisible wall instead
    – user232393
    Jun 9 '19 at 17:09
  • I have noticed in your code that @a is used, will this mean that all players on the server will be teleported back to the set coordinates?
    – Lithium
    Jun 9 '19 at 18:08
  • 1
    It means that all players are affected, but there is a filter, too, the part in the [ ], so it affects all players in that radius, basically
    – user232393
    Jun 9 '19 at 18:10

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