Using scoreboards as varibles

In my minecraft map, I have a scoreboard, mainvars, that I made by running /scoreboard objectives add mainvars dummy
,
that has 1 player called var I made by running /scoreboard add players var mainvars 5
.
I tried to test if var = 5 with /testfor var[score_mainvars=5]
, but it doesn't work.
EDIT:but /testfor @p[score_mainvars=5]
works? I'm confused.
Any help?
Best Answer
You cannot use a player's name in place of an @ selector. If you want to test for someone with a certain name, use the name
argument:
/testfor @a[name=var,score_mainvars=5]
Keep in mind that @a selects player entities that exist somewhere in the world, not every single possible username. e.i. this will only work if there is actually a player called "var" currently on the world.
If you're wanting to test for a scoreboard objective value, rather than an online player, then you should use the /scoreboard players test
command. The syntax is:
/scoreboard players test <player> <objective> <min> <max>
Pictures about "Using scoreboards as varibles"



Can you have multiple scoreboards in Minecraft?
Each 'display slot' can show one objective at a time, and multiple 'display slots' may be used for the same or different objectives.Minecraft Scoreboard Command Tutorial [1.18]
More answers regarding using scoreboards as varibles
Answer 2
Scoreboard assigns the value of a variable to each and every player. Take for eg- There is a variable called money. Now, it has no central value corresponding to the game, but it has a unique value for each and every player. And hence what you wrote later was correct.
Sources: Stack Exchange - This article follows the attribution requirements of Stack Exchange and is licensed under CC BY-SA 3.0.
Images: KoolShooters, Yan Krukov, Julio Lopez, RODNAE Productions