Contains objectives and participants for the scoreboard.

Hierarchy

  • ScoreboardObjective

Constructors

Properties

displayName: string

Remarks

Returns the player-visible name of this scoreboard objective.

Throws

This property can throw when used.

id: string

Remarks

Identifier of the scoreboard objective.

Throws

This property can throw when used.

Methods

  • Parameters

    • participant: string | Entity | ScoreboardIdentity

      Participant to apply the scoreboard value addition to.

    • scoreToAdd: number

    Returns number

    Remarks

    Adds a score to the given participant and objective.

    This function can't be called in read-only mode.

    Throws

    This function can throw errors.

    Example

    addPlayerMoney.js

    import { world } from "@minecraft/server";

    const money = world.scoreboard.getObjective("money");
    const player = world.getPlayers()[0];
    const currentScore = money.addScore(player, 100);
    player.sendMessage(`Your current score is ${currentScore}`);

    Example

    removeScore.js

    import { world } from "@minecraft/server";

    const money = world.scoreboard.getObjective("money");
    const player = world.getPlayers()[0];
    const currentScore = money.addScore(player, -100);
    player.sendMessage(`Your current score is ${currentScore}`);

  • Parameters

    Returns number

    Remarks

    Returns a specific score for a participant.

    Throws

    This function can throw errors.

  • Returns ScoreboardScoreInfo[]

    Remarks

    Returns specific scores for this objective for all participants.

    Throws

    This function can throw errors.

    Example

    topPlayer.ts

    import { world } from "@minecraft/server";

    const money = world.scoreboard.getObjective("money");
    var scoreArray = money.getScores();
    scoreArray.sort(function (a, b) {
    return b.score - a.score;
    });

    console.log(scoreArray.map((score) => score.participant.displayName));

  • Parameters

    Returns boolean

    Remarks

    Returns if the specified identity is a participant of the scoreboard objective.

    Throws

    This function can throw errors.

  • Returns boolean

    Remarks

    Returns true if the ScoreboardObjective reference is still valid.

  • Parameters

    Returns boolean

    Remarks

    Removes a participant from this scoreboard objective.

    This function can't be called in read-only mode.

    Throws

    This function can throw errors.

  • Parameters

    Returns void

    Remarks

    Sets a score for a participant.

    This function can't be called in read-only mode.

    Throws

    This function can throw errors.

    Example

    resetMoney.js

    import { world } from "@minecraft/server";

    const money = world.scoreboard.getObjective("money");
    const player = world.getPlayers()[0];
    money.setScore(player, 0);
    player.sendMessage(`Your score has been reset.`);