Minecraft – How to “block off” an area with command blocks

minecraft-commandsminecraft-java-edition

How can I make a certain radius around a command block, somewhere only certain people can enter, even with /tpo. I want the command block to teleport the people who try to teleport inside that radius to be teleported to certain coordinates. Is that possible? If so, how?

Best Answer

You could do it by TPing all players not in a specified team away.

Add all players that you want to access the area to a team:

/scoreboard teams add [team name]
/scoreboard teams join [players...]

Then you need a command block in Repeat mode in the area, you can use needs redstone or always active, but I would suggest that you at first run a redstone wire with repeaters and a lever at the end for testing.

Repeating command block command:

/tp @e[r=[range in which players cannot access the area],team=![name of the team that can access the area]] ~40 ~ ~ [you can change the location]

Example:

/tp @e[r=10,team=!access] ~20 ~ ~