Minecraft – How to teleport someone to spawn based on team and position

minecraft-commandsminecraft-java-edition

I'm trying to make it so that a specific player who enters a region, anywhere between 730, 0, 110 and 760, 256, 137, gets teleported to spawn. I managed to make it so whenever anyone entered the area it would teleport the target player to spawn, but my main goal is to make it so that I can walk around freely while my friend is locked out without having him teleported to spawn 10 times every second. I tried using teams but that wouldn't work either, but maybe I'm just doing it wrong.

I've been using this command, goawayree being the team I created with the target in it.

execute if entity @a[team=goawayree][x=730,y=0,z=110,dx=50,dy=256,dz=50] run tp @a[team=goawayree] 0 72 0

this was using radius' as i couldnt figure out how i would make a set boundary without 300 armor stands and 13 different headaches.
if this isnt possible please please please point out a similar way to do this, ive been looking for solutions online for about 3 days.
thanks for the help in advance

Best Answer

With selectors, all filters(or the values in the square brackets) go in one array(square brackets). It would be in the form of name=value,name=value,name=value and it keeps going until you don't have any other filters to add. So you need to combine team=goawayree with x=730,y=0,z=110,dx=50,dy=256,dz=50 in one array to make [team=goawayree, x=730,y=0,z=110,dx=50,dy=256,dz=50]. You also are teleporting everyone on the goawayree team, when any player is in the rectangular prism x=730,y=0,z=110,dx=50,dy=256,dz=50. You can fix this by using just a tp command, selecting everyone on goawayree team in the rectangular prism, and tping them to spawn. Here is how you do that.

tp @a[team=goawayree, x=730,y=0,z=110,dx=50,dy=256,dz=50] 0 72 0

That command in theory should work. If you have any problems let me know.