tag @s add swap_temp
execute as @a[distance=..250,gamemode=!spectator,sort=random,limit=1,tag=!swap_temp] run tag @s add swap_target
execute at @a[sort=nearest,limit=1,tag=swap_target] rotated as @a[sort=nearest,limit=1,tag=swap_target] run tp @s ~ ~ ~ ~ ~
execute as @a[sort=nearest,limit=1,tag=swap_target] rotated as @a[sort=nearest,limit=1,tag=swap_temp] run tp @s ~ ~ ~ ~ ~

tellraw @s ["",{"text":"You swapped places with ","color":"aqua"},{"selector":"@a[tag=swap_target]","color":"white"}]
tellraw @a[sort=nearest,limit=1,tag=swap_target] ["",{"text":"You swapped places with ","color":"aqua"},{"selector":"@s","color":"white"}]

execute at @s run playsound minecraft:entity.illusioner.mirror_move player @a ~ ~ ~ 1 2
playsound minecraft:entity.illusioner.mirror_move player @a ~ ~ ~ 1 2

execute at @s run particle minecraft:reverse_portal ~ ~1 ~ 0 0 0 2 50
particle minecraft:reverse_portal ~ ~1 ~ 0 0 0 2 50

tag @s remove swap_temp
tag @a[tag=swap_target] remove swap_target