How to make a message show for everyone when closest player is on the correct team
I am making a custom map with my friend, and at one part, you have to get scanned. If you're on team green it should say "Scan completed," but if they're on team red, it shouldn't say anything.
execute if entity @p[team=green] run say "Scan completed"
I've tried this code so far but didn't get any result.
What could be my issue here?
The code you have does work in Minecraft Java 1.19.2. I'm pretty sure it works in many earlier versions as well.
If you get any problems it might be because the command block is targeting a different player, remember that the selector:
@pis selecting the closest player to the command block.
You might also have named the team wrong.
To add a team you would use this command:
/team add "display name"
/team add green "Green"
This will add team
greenwith the display name
Green. Remember that the names are case sensitive so if you used a lowercase when creating the team you need to use lowercase when testing for it.
And the name of the team is the
greenpart, you can't(at least not to my knowledge) test for the display name of a team.
If you are on a server make sure that command blocks are enabled in the server properties.