How can I add player's to a list?

How could I make a list of all players in the server and display IntValue's or BoolValue's each player has using GUI’s.

Something like this:

How should I go about this?

Any help appreciated!

3 Likes

Anyone have any idea how to go about this?

Depends just exactly what you need. I’m getting leaderboard vibes, so if you don’t need a custom looking one then you can try out leaderstats. Roblox made their own article on how to do it.

If you want a custom one, that looks different, that would be slightly more challenging yet doable.

Maybe I wasn’t clear enough in the OP, I’m asking how could I make a list of players in the server using GUI’s.

You’d loop through the list of players by accessing the Players service and using the :GetPlayers() method inside a local script.
Example below.

local Players = game:GetService('Players')

for i, player in ipairs(Players:GetPlayers()) do
    -- Create some GUI based on the player objects.
end

To add onto this, you should also fire this function each time a player joins or leave. Don’t forget to destroy the previous GUI first

1 Like

Yep! Listening to the PlayerAdded and Removed event is crucial to keep the leaderboard updating live and correct.

1 Like

I assume you’ve created the player list gui, so;

  1. Create a placeholder frame in a separate folder
  2. Everytime a player joins, server should send a request to update the leaderboard; you can do it with remoteevents
  3. Once the client(i assume its a gui, not a part inside workspace) gets the remote call, it duplicates the placeholder frame and changes its’ properties to appropriate ones(player name, money, etc etc)
  4. Done!

If you have any questions, feel free to ask

1 Like

That’s what I had in mind, simply cloning a placeholder and updating the name and stats accordingly.

Could you give a small code example of this?

I did that, but it doesn’t detect when other players have joined, it only detects when you join.

It should detect the player joining regardless of who joins. Can we see what your code look like?

This is what I’m currently doing:

while wait(5) do
	for i, player in pairs(Players:GetPlayers()) do
 -- create a gui for player
		
	end
end
while wait(0.1) do
local p = game.Players:GetPlayers()
for i = 1,#p do
if not (guihere):FindFirstChild(p[i].Name) then
local a = Template:Clone()
a.Parent = (guihere)
a.playername.Text = p[i].Name
else
local h = (guihere):GetChildren()
h.Money.Text = p[i].leaderstats.Money
h.playername.Text = p[i].DisplayName
end
end

Have you tried doing game.Players.ChildAdded and game.Players.ChildRemoved instead of PlayerAdded?

Obviously not optimal however it’d probably be miles better than constantly looping for players. Could of sworn I did something like this awhile ago however it was years ago and can’t remember specifics.

This is my code so far:

local rs = game:GetService("ReplicatedStorage")
local Player_Stats = rs:WaitForChild("Player_Stats")

game.Players.ChildAdded:Connect(function(player)
     local Clone = Player_Stats:Clone()
     Clone.Parent = script.Parent
     Clone.PlayerName.Text = player.Name
end)

(Player_Stats is a frame for each player that we are cloning to the player list)

It only adds a frame for the local player while this is all being done in a server-side script, why?

https://create.roblox.com/marketplace/asset/7066294774/Leaderboard?pageNumber=1&pagePosition=3&keyword=Leaderboard

You can use this plugin to help, it will insert a script with everything you need and its easy to customize.
If you want to do it manually then:

Setup a Ui with a sample row and a UI list layout. Set the sample row to be not visible

game.Players.PlayerAdded:Connect(function(player) --detect a player to join
    local newrow = Ui.samplerow:Clone()
    newrow.Visible = true
--Set the correct values such as player.name ect

end)

Ill screenshot an example layout:

edit:
image
and how it would look like (this is just an example, I know the ui design is horrific)

I have done that already.

Why is that any different from my code? My code: ↓

I didn’t see that post at the time of writing, you should mark the forum as solved so that people dont reply on a solved topic like me.

Its not solved… It doesn’t work.