Question about scoreboards


#1

I have this code:

public void playerCustomScoreboard(Player player) {

	Jugadores jugador = new Jugadores(plugin_m, this, player.getUniqueId());
	
	Scoreboard prueba = player.getScoreboard();
	
	 Objective obj = Objective.builder()
                .name("prueba")
                .criterion(Criteria.DUMMY)
                .displayName(Text.of(TextColors.RED, player.getName()))
                .build();
     
	 obj.getOrCreateScore(Text.of(TextColors.GOLD, "Balance: $", jugador.getPlayerBalance())).setScore(2);
	 obj.getOrCreateScore(Text.of(TextColors.GOLD, "Oficio: ", jugador.getJobName())).setScore(4);
	 
	 //Reset del scoreboard actual
	 for (Objective objective : player.getScoreboard().getObjectives()) {
            player.getScoreboard().removeObjective(objective);
     }
	 
	 prueba.addObjective(obj);
	 prueba.updateDisplaySlot(obj, DisplaySlots.SIDEBAR);
	 
	 player.setScoreboard(prueba);
	 
}

It triggers when a player logs into the server, but the problem is that everyone sees the scoreboard of the last player joined, anyone can tell me why?


#2

I think you have to create a new scoreboard (Scoreboard.builder()) instead of using the player’s current one (player.getScoreboard()) because by default it’s the scoreboard shared for every player on the server.