Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

List of players from a table?

I'm making a gui and I want it to show all the players in the game

I made a table for all the players in the game:

local plrs = {} --Players in the game

game.Players.PlayerAdded:Connect(function(player)
	table.insert(plrs, player.Name)
end)

I already designed a gui for the player name, but I want it to duplicate for how many players there in the game. For example: If there are 4 players in the game, there will be 4 guis that show the player names from the game.

Also would this be a script or a local script?

3 comments

0

It is a User-interface, which makes it Local as it pertains to the Client. You also do not necessarily require a recorded array of the Players, as you can simply just instantiate a TextLabel—fitted within a UIListLayout-controlled Frame—that reads the Player's information derived from the Callback's parameter. You need to manage the Player's leaving as well through the 'PlayerRemoving' Event.

0

FYI: You can also get a collection of the Players in-game through the 'GetPlayers' method of the Players Service.

0

This is just my opinion here, but for readability purposes, I recommend you give more precise and meaningful identifiers. 'Players' > 'plrs'.

1 answer

Here's a tip.

If you're trying to make a sidebar of the list of players, use the client for that.

Getting current players, mainly do this when the GUI is first inserted.

for i,v in pairs(game.Players:GetChildren()) do

--Place your script to insert a frame into a list box.

end)

When a player joins or leaves, remove there box.

game.Players.PlayerAdded:Connect(function(plr)

--Place your GUI stuff here and add the frame to a list box

end)

game.Players.PlayerRemoving:Connect(function(plr)

script.Parent.PlayerList:FindFirstChild("Player_"..plr.Name)

end)

This discussion is preserved as it was. New answers, comments, and votes are closed.