Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

What would be best way to remove player from custom playerlist?

Asked by
Thetacah 712 Moderation Voter
10 years ago

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 leaderboardsthat 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.

0
It would depend a lot on how you have everything set up in the explorer. Perci1 4988 — 10y

1 answer

Log in to vote
0
Answered by
BlackJPI 2658 Snack Break Moderation Voter Community Moderator
10 years ago

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)
0
I thought about playerremoving too, then putting the names in a table. That works too though. For removing player from leaderboard, should I delete everything and re-display them? Their would be a blank space with a gui removed if not. Thetacah 712 — 10y
0
I would delete the player's gui object, and then tween all the rest of the ones with a lower absolute y position up the height of the deleted gui object BlackJPI 2658 — 10y
Ad

Answer this question