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

How to find all players in a server and store the names in a GUI?

Asked by 9 years ago

So I have been really bad with this and I want to make a script where it will find all the players in the server and list them in a GUI now I am not asking for you to script it for me just how would I go about it and where should I learn how to do this? Now I would say what I have tried but the truth is I haven't tried much because I have no idea where to start with it please help this is holding me back from alot of the ideas I have for roblox games.

1 answer

Log in to vote
1
Answered by
Validark 1580 Snack Break Moderation Voter
9 years ago

My advice, use a local script to get the names of the Players.

Inside the localscript, put something along these lines:

local PlayerList = script.Parent.Parent.Parent.Parent --Adjust the amount of Parents for where the script is

function CreatePlayerlist()
    for a,r in pairs(script.Parent:GetChildren()) do --Clear old Names
        if r.ClassName ~= "Script" then
            r:Destroy()
        end
    end

    for i,v in pairs(PlayerList:GetChildren()) do --Adds names to Playerlist
        local PlayerButton = Instance.new("TextLabel",script.Parent) --Forgive my naming, super tired
        PlayerButton.Text = v.Name -- v is the actual object of Player, so access name property
        PlayerButton.Position = UDim2.new(1, -30, 0, (i-1)*16)
        PlayerButton.Size = UDim2.new(0, 30, 0, 16)
    end
end

Playerlist.ChildAdded:connect(CreatePlayerlist)
Playerlist.Removed:connect(CreatePlayerlist)
CreatePlayerlist() --Startup


0
Keep in mind, I wrote that script off the top of my head at nearly 4 AM without testing, so it could be dangerous. Sorry if I cause more problems. Validark 1580 — 9y
0
Using a line of Parents to find the Player/Players is HIGHLY inefficient, The 'Players' variable should be `game:GetService("Players")`, and when referencing it, simply just use the Players variable. Other than that, most of the script is o-kay. unmiss 337 — 9y
0
Thanks :D CybeTech 37 — 9y
Ad

Answer this question