#SetScore boolean parameter add breaks the score.

1 messages · Page 1 of 1 (latest)

spare grotto
#

why doesnt my setscore add parameter work

const setScore = (objective, target, amount, add = false) => {
  try {
      const scoreObj = world.scoreboard.getObjective(objective);
      const score = (add ? target.scoreboardIdentity?.getScore(scoreObj) : 0) + amount;
      if (typeof target === 'string')
          scoreObj.getParticipants().find(v => v.displayName == target)?.setScore(scoreObj, score);
      else target.scoreboardIdentity.setScore(scoreObj, score);
      return score;
  } catch { return NaN };
}```
#

it just sets the score to 0

spare grotto
#

yooo

#

thanks

lofty shell
spare grotto
#

ok well turns out it works with regular players but i need it to work with fake players too

#

with fake players it still turns it to 0

lofty shell
#

Use runCommand if scoreboard Identify don't exist

spare grotto
#

well i cant do that bc in my code i want to remove 1 from a score every second but if i do player.runCommand it will run for all the players so it will remove 2 per second if there are 2 players

#

imma try do a small example

spare grotto
#

so like i get all the players, i test for their teamname, i check for the "timer" (i made up a name), and if it was greater than 0 it would run a command as all the players which their team had a score greater than 0 but that means if 2 players are on the same team it will remove 2 every second not 1

#

also at the end of runInterval i forgot }, 20)

#

but yeah

#

but its not a point of this only thing i can prob tihnk about ways to fix it i just wanna have a setscore that works with fake players too