Sourced By Bedrock Commands Community Discord
This system allows you to track how many players/entities are there on your world and run your desired commands based on the values obtained.
Note: you cannot track entities in unloaded chunks though players can still be tracked regardless.
To be typed in chat:
/scoreboard objectives add total dummy
/scoreboard players set onlinePlayers total 0 /execute as @e [type=player] run scoreboard players add onlinePlayers total 1 #Your Commands Here (examples) /execute if score onlinePlayers total matches 4.. run title @a actionbar Enough players to start game. /execute if score onlinePlayers total matches ..3 run title @a actionbar Not enough players.
Here we have used a FakePlayer name
onlinePlayers and targeting
@e [type=player] to track how many players are currently on the world. However you may use any FakePlayer name and target any entity you might need. Such as
Similarly we're running a
/title command as an example;
- a) when there are 4 or more players
- b) when there are 3 players or less
You can edit this as well to suit your need.
- The first two commands in the system sets the FakePlayer name's score to 0 (here
onlinePlayers) and from each loaded entity we want to track (here
type=player) it will add a score to the specified FakePlayer name (here
Now based on the values obtained we can use the
/execute if score command to run our desired commands when certain values are met.
nany number n
n..any number n and above
..nany number n and below
n1..n2any number n1 to any number n2.