How to make player table

i want to make a player table and a button for each player, i need something like this:

how do i make a local script for it?

1 Like

I think you can use game.Players:GetPlayers()

yes, but how do i make it so that their username is written? like the first player found is on the first button, second player found is on the second button etc?

You can use for loops

for _,Players in pairs(game.Players:GetPlayers()) do
       
end

You can get their names by using Players.Name

yes but how do i make it enter the players name in the first, then the second one in the second, since if i put just button.Text = Player.Name, then it will just be one player, and not all

Are you using UIListLayout

if yes then you can just create a template ui and just copy them for each player that are in the server

for _, player in pairs(game.Players:GetPlayers()) do
    --create button
    button.Text = player.Name
end

It will do for every player, that’s why it’s called cycle for

  1. Make a ScrollingFrame inside a ScreenGui . Make sure it has AutomaticCanvasSize set to Y. Add a UIListLayout within it.

  2. Make a template player frame you will use for each player. You can use a TextLabel called PlayerName for the name.

  3. Make a LocalScript inside the ScreenGui. Parent your template player frame to it.

Write this code:

local players = game:GetService("Players")

local holder = script.Parent:WaitForChild(--[[ScrollingFrame name]])
local example = script:WaitForChild(--[[player frame name]])

local function destroyCurrent()
    for _, v in next, holder:GetChildren(), nil do
        if v:IsA("UIListLayout") then continue end
        v:Destroy()
    end
end

local function update()
    destroyCurrent()
    for _, player in next, players:GetPlayers(), nil do
        local clone = example:Clone()
        clone.PlayerName.Text = player.DisplayName
        clone.Parent = holder
    end
end

task.spawn(update)
players.PlayerAdded:Connect(update)