Adding a Scoreboard, where is my mistake?

Hey guys,

I am trying to add a scoreboard to the player on the PlayerJoinEvent. Since this didn’t work, I added a test command to add the scoreboard, because I thought that the player might not be ready when the PlayerJoinEvent gets fired.

Here is my CommandExecutor:

public class test implements CommandExecutor {
    public CommandResult execute(CommandSource src, CommandContext args) throws CommandException {
        Player player = (Player) src;
        player.sendMessage(Text.of("Hello World!"));

        Scoreboard scoreboard = Scoreboard.builder().build();
        Objective objective = Objective.builder().name("Health").displayName(Text.of(TextColors.BLUE, "Health")).criterion(Criteria.DUMMY).build();

        scoreboard.updateDisplaySlot(objective, DisplaySlots.BELOW_NAME);



        return CommandResult.success();

When I execute this command, it only sends me the message but no scoreboard appears.

Thanks in advance,

All of your code is fine - the issue is with the display slot you’re using.

DisplaySlots.BELOW_NAME will only allow you to see the scores of other players, which will appear beneath their nametag in-game. However, just as you can’t see your own nametag in-game, nor can you see your score for an objective in the BELOW_NAME displayslot.

To verify that this is working, you could set the objective in the SIDEBAR display slot in addition to BELOW_NAME.

At ClientConnectionEvent.Join, you’re able to properly set the Scoreboard on a player, or anything else - that’s the earliest point at which the Player is fully initialized.

Hope this solves your problem!

1 Like

Thanks a lot.
Didn’t see the BELOW_NAME even after several times of re-reading :frowning:
Works fine now.