Hey folks.
In the past I've created several custom leaderboards
. Though, I've always made them on keydown
it would show up, so removing names wasn't an issue. I'm now moving on to making more professional custom leaderboards
that will stay on your screen. Whilst a player
is removed from the game which way would be most efficient to update the current leaderboard state? Deleting all the current names, then re-adding them would be the simple way. I'm not sure how I feel about doing that, though. It seems very inefficient.
Thanks in advance.
The simplest way I can think of is using the PlayerRemoving event of Players. You'll need to optimize it for your leaderboard specifically but it is very simple to do. I'd suggest adding all players them to a list of characters somewhere like ReplicatedStorage so you can easily remove them later.
local playerList = game.ReplicatedStorage.PlayerList -- Any object named PlayerList in ReplicatedStorage game.Players.PlayerAdded:connect(function(player) local value= Instance.new('ObjectValue', playerList) -- Could be any object value.Name = player.Name end) game.Players.PlayerRemoving:connect(function(player) if playerList:FindFirstChild(player.Name) then playerList:FindFirstChild(player.Name):Destroy() end end)
Now your list of players updates, but you'll need to make a check when it updates. The reason I suggested putting it in ReplicatedStorage is so you can use ChildAdded and ChildRemoved events in your leaderboard script.
local playerList = game.ReplicatedStorage.PlayerList playerList.ChildAdded:connect(function(child) -- Add player to the leaderboard end) playerList.ChildRemoved:connect(function(child) -- Remove player from the leaderboard end)