local frame = script.Parent local labels = {} for i = 1, game.Players.MaxPlayers do labels[i] = frame:WaitForChild("Player"..i) end local players = game.Players:GetPlayers() for number = 1, #labels do labels[number].Text = tostring(players[number] or "") end
08:39:02.906 - Infinite yield possible on 'Players.Player1.PlayerGui.PlayerListUI.PlayerListFrame:WaitForChild("Player11")'
08:39:02.908 - Script 'Players.Player1.PlayerGui.PlayerListUI.PlayerListFrame.LocalScript', Line 7
08:39:02.909 - Stack End
I have 10 TextLabels inside the frame, and I have it set so the MaxPlayers is 10 per server. It works when I join the actual game, but it doesn't work in studio, and I have the error that is printed in the output above.
You don't need to be checking how many players there are, you can just iterate through the labels and set the text of that label to the name of that player (or blank if there are no more players.)
local frame = script.Parent local labels = {} for i = 1, game.Players.MaxPlayers do labels[i] = frame:WaitForChild("Player"..i) end local players=game.Players:GetPlayers() for number = 1, #labels do labels[number].Text = tostring(players[number] or "") end
edit: If you want it to update whenever a player joins/leaves, connect it to PlayerAdded and PlayerRemoving:
local frame = script.Parent local labels = {} for i = 1, game.Players.MaxPlayers do labels[i] = frame:WaitForChild("Player"..i) end function update() local players=game.Players:GetPlayers() for number = 1, #labels do labels[number].Text = tostring(players[number] or "") end end game.Players.PlayerAdded:connect(update) game.Players.PlayerRemoving:connect(update) update()