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

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

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

✓ Accepted answer

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


3 comments

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.

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.

0

Thanks :D

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