Arqade Asked by RoyalGaming369 on May 13, 2021
I need to run a command for @a
that doesn’t have a score of 1. Is there a way to do that? (0 wont work because the default is no score, not 0). I would list my command but I’m not sure of the format. I want it to set all players without a score of 1 to /gamemode
Survival. Any suggestions?
You cannot directly target somebody that has no score instantiated.
If you absolutely need to avoid any score except 1 (i.e. a score of 0 or lower, 2 or higher, or no score at all), you can label players that have a score of 1 and then target players without that label:
/scoreboard players tag @a[score_OBJ_min=1,score_OBJ=1,tag=!one] add one
/gamemode survival @a[tag=!one]
/scoreboard players set @a[tag=!one] OBJ 1
The benefit here is that no commands here are constantly running, as players that did match will no longer do so.
An alternative is to add 0 to their score in order to instantiate it with a default of 0, which will not change their score if they're already tracked:
/scoreboard players add @a OBJ 0
/gamemode survival @a[score_OBJ=0]
/scoreboard players set @a[score_OBJ=0] OBJ 1
The first /scoreboard
command is always running, which may not be desirable.
Correct answer by Skylinerw on May 13, 2021
As of 1.13, the /execute unless score
command can now target players that don't have a score instantiated. The trick is to find a condition that seems to always be true; it'll fail only when a score is not present:
execute as @a unless score @s objective = @s objective run tag @s add noScore
execute as @a[tag=noScore] run ...
Answered by ExpertCoder14 on May 13, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP