#How do I get a score from a scoreboard
1 messages · Page 1 of 1 (latest)
you can use system.runInteerval()
Basically I want to connect these to use runCommand to display a score of a player with a titleraw command
What abt the score
Ik I can just use the in game stuff like *
But that's for smth else
Oh wait nvm I need those separated
system.runInterval(() => {
world.getAllPlayers().forEach(player => {
let score = get the score of the player you can use the wiki to learn how
player.onScreenDisplay.setTitle(`${score}`)
}
}, 40);```
Bru that's what I need the let score = get the score I don't understand the wiki 😭
this server isnt there to code for u its just a help server
...
getting the score of the player is basic knowledge so you should learn how
i give you all script already except for 1 line
here you can learn about scoreboard
Btw I changed my runCommandAsync into runCommand like u said and it still doesn't work
are u trying to do a title or actionbar?
you have to get the scoreboard property of world (world.scoreboard), then get an objective with .getObjective(<id>) and finally .getScore(<player>)
btw the <player> in getScore() method has to be Player class
system.runInterval(() => {
for (const player of world.getPlayers()) {
const score = world.scoreboard.getObjective(<id>).getScore(player);
player.onScreenDisplay.setActionBar(`Score: ${ score || 0 }`);
}
});```
alr thank u so much
if i want to do 2 of these do i have to copy the whole thing again (after the system.runInterval)
what are you trying to do exactly?
and no, just do it inside the players loop
lets say if i want to make a kills scoreboard and deaths and lets say ik how to
like how to add kills and deaths
now i want to display it without runCommand
i need to do const for the score right?
so like
i want 2 scores
kills and deaths
what i just said tho
i mean i need even more but its just to understand how to do two scores in the shortest way
you have to get the two objectives and use the getScore method on both
alr
system.runInterval(() => {
for (const player of world.getPlayers()) {
const { scoreboard } = world;
const kills = scoreboard.getObjective("kills")?.getScore(player);
const deaths = scoreboard.getObjective("deaths")?.getScore(player);
player.onScreenDisplay.setActionBar(`Kills: ${ kills || 0 } | Deaths: ${ deaths || 0 }`);
}
});```
const getScore = (player, objective) => {
return world.scoreboard.getObjective(objective)?.getScore(player.scoreboardIdentity);
}
system.runInterval(() => {
for (const player of world.getAllPlayers()) {
const kills = getScore(player, "kills");
}
})
wait, is it necessary to use scoreboardIdentity? i thought it was just an Entity class argument
maybe that's the reason i had problems with getting scores