Alright, so the owner/developer of the server I am working on gets bug reports from the players for the leaderboard which is in a floating text. It does not refresh when any of the top 10 players get a win. We are both trying to find a method to refresh the leaderboard while the player is in-game, because what we did before was just adding the particle on the join event to the player who joins. We explained them this is not a bug, they have to re-join in order to get the refreshed leaderboard. Is there any way to auto refresh them in a task? Keep in mind that there are spawning to the player every time he joins, so you can't get an actual entity id. Also, the leaderboards are being shown in the other worlds when I only spawned them to the Lobby. Can this be fixed?
Save the floating text object you are spawning to the players. Set the text of the floating text particle, before spawning it again to the player. The previous floating text entity will be despawned and a new one will be spawned with the updated text.
Here's an example: PHP: private $floatingTextParticle;private $spawnedTo = [];public function onEnable(){ $this->floatingTextParticle = new FloatingTextParticle(new Vector3(0, 128, 0), "DaPigGuy", "Best Pig of the Month");}public function spawnFloatingTextParticleTo(Player $player){ $player->getLevel()->addParticle($this->floatingTextParticle, [$player]); $this->spawnedTo[$player->getId()] = $player;}public function despawnFloatingTextParticleTo(Player $player){ $this->floatingTextParticle->setInvisible(); $player->getLevel()->addParticle($this->floatingTextParticle, [$player]); $this->floatingTextParticle->setInvisible(false); unset($this->spawnedTo[$player->getId()]);}public function setFloatingTextParticleText(string $text){ $this->floatingTextParticle->setText($text); foreach ($this->spawnedTo as $player) { if(!$player->closed){ $player->getLevel()->addParticle($this->floatingTextParticle, [$player]); } }}
Uhh, sorry for that but I forgot to say that I am spawning 1 entity for each player in the list. I would really like to make that but first, would you tell me how to fix the world bug?
Are you spawning a floating text particle with different text to every player? If not, spawning one for each player is unnecessary. As for your 2nd issue, you can check the level the player is in after a level change. If it's not the correct level, despawn the floating text (shown above).