I'm making a scoreboard which displays the online users as a string like this So to update this (when a player joins the server) I have tried resetting that value with .resetScore. However this does not work, and results in this I have no idea why it's doing this. Here is my code Code:java public void updateSB(){ for(Player p:Bukkit.getOnlinePlayers()){ if(p.getScoreboard() != null){ Scoreboard board = p.getScoreboard(); Objective o = board.getObjective(DisplaySlot.SIDEBAR); for(OfflinePlayer player : board.getPlayers()) { if(player.equals("" + getPlayerCount())){ board.resetScores(player); } } o.getScore(Bukkit.getOfflinePlayer("" + getConfig().getString("online-value").replaceAll("&", "\u00A7").replaceAll("ply", "" + Bukkit.getOnlinePlayers()))).setScore(8); p.setScoreboard(board); } } } This method uses one other method called getPlayerCount. The setter and getter for that can be seen here Code:java private int players = 0;public void setPlayercount(int playercount){ players = playercount; } public int getPlayerCount(){ return players; } I'm setting the player count in a join event Code:java @EventHandler public void onJoin(final PlayerJoinEvent e){ setPlayercount((Bukkit.getOnlinePlayers().length - 1)); } I'm subtracting one from that because when you call the Bukkit.getOnlinePlayers it includes the player that had just joined.
Simply put, resetting scores won't work. You'll have to destroy the objective every time you want to update. You can have a look at my API: SideAPI, (GitHub), so you can see what it's doing.
Bionicrm I don't understand why it won't work. The way I have it now, it actually works fine until someone quits. When a player joins it updates fine but when a player quits it does whats shown in the second screenshot in the op.
To update it you'll have to loop through all your offline players, check for the one that has 8 as a score (which is the scoreboard slot of your playercount). Then you reset the score for that offline player and create a new one with the same score and updated playercount. Some snippets that might be useful for you: Code:java for(OfflinePlayer offp : scoreboard.getPlayers()) { int i = objective.getScore(offp).getScore(); if(i == 8) { scoreboard.resetScores(offp); fake(new playercount here).setScore(8); }} public Score fake(String fakeName) { return objective.getScore(Bukkit.getOfflinePlayer(fakeName));}