How do I print a list of players or print them onto a label?

So, I’m trying to print them out onto a textlabel. I want it to get the names of everyone on the server and print them onto a label. In theory, I have something like this scripted:

local getplaying = game.Parent.GetChildren()
	local label = Instance.new("TextLabel", game.Workspace.AECMD.SurfaceGui.ScrollingFrame)
	label.Text = getplaying
	label.ZIndex = 2
	label.Size = UDim2.new( 1 , 0, 0 , 10)
	label.TextScaled = true

	label.TextXAlignment = "Left"
	label.TextYAlignment = "Top"
	label.TextColor = Color3.new(255,255,255)
end
1 Like

What is this one? Is it a string?

string is defined as getplaying in local game.Players:GetDescendents()

That’s an instance. It should be

local players = game:GetService("Players")
local str=''
for i,o in players:GetPlayers()do
str..=o.Name.."\n"
end

getplaying = str

Not sure if I got it right but you want to loop through every Player in-game and need to print it out right?

You can use a loop for that :slight_smile:

for i, v in pairs(game.Players:GetChildren()) do
print(v.Name)
end

In this loop, “v” is the player.

Yup, that worked and did it correctly! thank you!

This should work.

local players = game:GetService("Players")

local root = game.Workspace.AECMD.SurfaceGui
local frame = root.ScrollingFrame

for i, v in pairs(players:GetChildren()) do
   local newLabel = Instance.new("TextLabel")
   newLabel.Parent = frame
   newLabel.Text = v.Name
   newLabel.ZIndex = 2
   newLabel.Size = UDim2.new(1, 0, 0, 10)
   newLabel.TextScaled = true
   newLabel.TextXAlignment = "Left"
   newLabel.TextYAlignment = "Top"
   newLabel.TextColor = Color3.fromRGB(255, 255, 255)
end

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.