Minecraft – way to testfor a collective scoreboard

minecraft-commandsminecraft-java-edition

I play on a server, and I want to make a multiplayer minigame that uses scoreboards. I want to be able to testfor the collective amount of people with the a scoreboard that adds up to a certain amount. Example: On singleplayer, the one person playing will have 10 points, but on multiplayer, 2 people will have 5 points making a collective score of 10 Points. Is it possible to testfor this?

Best Answer

You can use /scoreboard players operation to add all scores up and put them into one score. These two commands put the sum of all scores in the scoreboard "hello" into the score "sum" for the real or imaginary player "Horst":

/scoreboard players set Horst sum 0 /scoreboard players operation Horst sum += * hello

Scoreboard "sum" has to exist already, but Horst doesn't. This iterates one every entry in the scoreboard "hello" and adds its value to Horst's score, which is initially 0. You can also replace * with a target selector.