Scoreboards above own head

Hey,
I created a topic, asking how to add a scoreboard.
Now I know, that I can create a scoreboard with following code:

Scoreboard scoreboard = Sponge.getGame().getRegistry().createBuilder(Scoreboard.Builder.class).build();
        Objective obj = Sponge.getGame().getRegistry().createBuilder(Objective.Builder.class).criterion(Criteria.DUMMY).name("Village-Name").displayName(Text.of("Village-Name")).build();
        obj.setDisplayName(Text.of(player.getName()));
        scoreboard.addObjective(obj);
        player.setScoreboard(scoreboard);
        scoreboard.updateDisplaySlot(obj, DisplaySlots.BELOW_NAME);

As you can see, the scoreboard’s position is above the players head.

What is the problem?
The board doesn’t appear above the head of my player, it does appear above everyone’s head, but player.getName() is the name of my player.
Example: When I see other players, above everyone’s head is a scoreboard with my name.

This is not how it should work. Everyone should have his own name above his head…

1 Like

What do you mean? Could you post a screenshot with where you’re trying to display it?

That’s how it works. When you call player.setScoreboard(scoreboard), you set the scores that are displayed to that player. Let me know if you need clarification.

Players already have their own names displayed above their heads.

Example: I’m with 3 Minecraft accounts online. Every player has a scoreboard (Content: player.getName();)
The problem: When I look at the other 2 players, above their head stands “Hitzk0pf”, but I want to see their name above their heads.
Do you understand me now? :slightly_smiling:

I think you’ve misunderstood how scoreboards work.

By itself, an Objective doesn’t actually cause anything to be displayed. Instead, the Scores added to an Objective are displayed on the client, depending on which display slot is set for the Objective in question.

Setting an objective in DisplaySlots.BELOW_NAME causes every player to have their score for said objective displayed underneath their nametag (you need to be fairly close to be able to see it), along with. It looks like this (source: http://static.planetminecraft.com/files/resource_media/screenshot/1312/Scoreboards_5116889.jpg)

Where ‘20’ is the score, and ‘Health’ is the display name of the objetctive in DisplaySlots.BELOW_NAME

To accomplish what you want, you’d need to do something like this:

obj.getOrCreateScore(Text.of(playerName)).setScore(20);

Where playerName is the name of the player to set the score for, and 20 is the score value.

1 Like

I do understand you. Let me explain the reason for this:

First, players that are viewing a scoreboard (the ones that you call setScoreboard on) see the Objective set to DisplaySlots.BELOW_NAME above every player’s head.

Second, if you call setScoreboard on a player, nobody else sees any change. Only the player you call setScoreboard on knows anything about that particular scoreboard or the Objectives within it.

Do you understand?

1 Like

Yes, I know that, but I don’t want that :smile:
Is there a way to set a scoreboard for a player? Like I said, I want to put (for example) the uuid of the player above his head (in the scoreboard).

You’d need a client mod to do that.

1 Like

The other option is to summon, and update an armor stand floating above the players with the name of what you want, with the marker interface like a hologram, but you would need to update the armor stands position constantly.

1 Like

Strange, recently I was on a server, that has this feature :frowning:

Mind showing us the server, or screenshots? someone may be able to work it out for you.

1 Like

So In this case, there stands a level above the players head, so they have to know, which player is “wearing” the scoreboard, don’t they?

No they don’t. Since it’s only the number that changes, it shows whatever score the player has for the given objective. but the display name of the objective is fixed and common for all the players visible to the viewer.

1 Like

First, sorry if you’ve misunderstood me. I don’t think I was very clear about per-player scoreboards vs objective display slots :slightly_smiling:

The simplest way to replicate the screenshot you posted is to have everyone using the same scoreboard. If you don’t explicitly set it, everyone will be using the server scoreboard (which is persisted accross restarts, and accessible through the /scoreboard command.

What you’ll probaby want to do is create a new scoreboard, then set it for all of your players. You can get a scoreboard by calling Scoreboard.builder().build, and calling setScoreboard on each Player with the instance you get back.

The code should look something like this:

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

        scoreboard.addObjective(objective);
        scoreboard.updateDisplaySlot(objective, DisplaySlots.BELOW_NAME);

        for (Player player: Sponge.getServer().getOnlinePlayers()) {
            objective.getOrCreateScore(player.getTeamRepresentation()).setScore(123);
        }

        for (Player player: Sponge.getServer().getOnlinePlayers()) {
            player.setScoreboard(scoreboard);
        }

This first creates a Scoreboard, then adds an objective to it, setting it into the BELOW_NAME display slot. It then loops over the connected players twice: Once to add a score for each player (replace 123 with some actual score value), and once to set their scoreboard to the fully initialized scoreboard.

The reason for looping twice is so that when a player gets their scoreboard set, it’s already fully initialized, with everyone’s score added.

1 Like

Ah, thanks! :slight_smile: Finally I got it, lol.

Thanks man :slightly_smiling: