Player list not working for multiple people

game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.PlayerList, false)


local plrs = game.Players

local serverMax = plrs.MaxPlayers

local template = script.Parent.Template

local list = script.Parent


for i = 0, serverMax do


	local label = template

	label.Name = i
	
end


while wait() do


	for i, label in pairs(list:GetChildren()) do
		if label:IsA("TextLabel") then


		if plrs:GetChildren()[i] then


			label.Text = "-["..plrs:GetPlayers()[i].Name.."]"

		else

			label.Text = "-[Loading]"
		end
	end
	end
	end

no errors in output. any help is appreciated

I think it is because you did not clone the gui, I think you just accidently forgot to.

Try

local label = template:Clone()

It only creates one because you’re not cloning it. On top of that, make sure to set the parent after you’ve named the Label if you want it to appear properly.

for i = 1, serverMax do
	local label = template:Clone()
	label.Name = i
	label.Parent = template.Parent
end

Outside of that specific issue under the assumption this is a custom PlayerList I wouldn’t recommend running a loop constantly getting the players. Have you possibly tried something along the lines of editing a desired TextLabel whenever a player leaves or joins the game?

Ok, this is really bad scripted, it has a lot of glitches and errors.

Here’s how to fix the TextLabel not appearing:

game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.PlayerList, false)


local plrs = game.Players

local serverMax = plrs.MaxPlayers

local template = script.Parent.Template

local list = script.Parent


for i = 0, serverMax do

	local label = template:Clone()
	label.Name = i
	label.Parent = list
	
end


while wait() do


	for i, label in pairs(list:GetChildren()) do
		if label:IsA("TextLabel") then


		if plrs:GetChildren()[i] then
			label.Text = "-["..plrs:GetPlayers()[i].Name.."]"

		else
			label.Text = "-[Loading]"
		end
	end
	end
	end

You have to Copy/Clone the TextLabel, not just change it’s parent.

Let’s say that there’s 10 people in the server. How is possible for 1 TextLabel to show 10 times?

Here’s how I’d achieve this, bare in mind you don’t have to use a “Hint” instance, I did for the sake of simplicity.

local players = game:GetService("Players")
local localPlayer = players.LocalPlayer
local playerGui = localPlayer:WaitForChild("PlayerGui")
local hint = Instance.new("Hint")
hint.Text = "Players: "
hint.Parent = playerGui

local starterGui = game:GetService("StarterGui")
starterGui:SetCoreGuiEnabled(Enum.CoreGuiType.PlayerList, false)

local function onPlayerAdded(player)
	hint.Text..=" "..player.Name.." |"
end

local function onPlayerRemoving(player)
	hint.Text = hint.Text:gsub(" "..player.Name.." |", "")
end

players.PlayerAdded:Connect(onPlayerAdded)
players.PlayerRemoving:Connect(onPlayerRemoving)
for _, arrayPlayer in ipairs(players:GetPlayers()) do
	onPlayerAdded(arrayPlayer)
end

When two players join:


When one player leaves:

I’m not wanting to clone it though. I have 8 textlabels with slots that are supposed to be filled before the game starts. How do I do this with already existing textlabels?

Name them like TextLabel_1; TextLabel_2 and change their text manually for every player.