Creating a Table with all players in game

Hello! I am trying to figure out how I would go about making a table of all players in game usernames. This should list out on a GUI each players username and a button next to their username. I have no clue about tables but I am getting fluent with scripting. If someone could break down how I would go about that, it would be much appreciated!

local playerTable = Game.Players:GetPlayers()

How does that ensure a button is there too?

First you want to make a frame with a UIListLayout instance inside it.

Make a function inside the script that will create a new frame and respective textlabels/buttons using a given parameter named player. Make sure to use LayoutOrder to help with ordering the frames.
Similarly, make a function that will delete this new frame.

Then you want to get all the players in the game the moment you open the window, along with any players that join or leave while it’s open.

Finally, you can call that function every time you loop through the current list of players, whenever a player joins, or the function that deletes the frame whenever a player leaves.

You may want to use the player’s name for the name of their frame to make the scripting easier. This isn’t exactly the most optimised method but it should work.


The title ask how you can create a table with all the players… Well, there’s the answer for that. Your post primarily asks for help with tables if I’m not mistaken?
If you want to separate that table in individual bits:

local playerTable = Game.Players:GetPlayers()

for index,player in pairs(playerTable) do
 -- Runs every time for each player element in the table

Here’s how it should look. The frames with usernames should be generated by the script.
(Ignore the weird icons, I’m using Vanilla icons)