I'm about to build a game mode and have 2 buttons with which you can select either Team Red or Team Blue. I thought about doing it like this: / tag @p add blue / red, so that the player comes into the team that is closest to the CommandBlock, which is often the one who presses the button. However, there's a problem when I press the TeamRot button, for example, but another player is closer. Then he comes in team red in contrast to me. Is there anything to add that player in TeamRot who also pressed the button?
Not really. The button is just a redstone signal.
Should work with @s. I have almost no idea about Command Blocks, but a quick Google search led me there. Try it out, maybe you can.
https://www.digminecraft.com/getting_started/target_selectors.php