How to put players usernames on text labes

How would I make it so every players username shows on multiple text labels?

image

2 Likes

I have provided a script you can try, if you have any questions about it feel free to ask

local template = script.Template --I suggest making a textlabel with all the settings you want on the textlabel and putting it inside the script
local Frame = script.Parent.Frame --Change this to the location that all the labels will go into

game.Players.PlayerAdded:Connect(function(plr) --When a player joins
   local label = template:Clone() --Create a clone of the label template
   label.Text = plr.Name --Change the text to the player's name
   label.Parent = Frame -- Change the parent of the label to the main frame all the labels will go to
end)

Since is an on their screen, put this to ScreenGui

local Players = game.Players

local TemplateTextLabel : TextLabel = script.TextLabel
-- Change this to your TextLabel that your own TextLabel design, Copy and Paste the TextLabel then put it to local script like this.

local Frame = script.Parent.Frame -- Change this to your Frame that has Player Value

for i,v in pairs(Players:GetPlayers()) do
	local val = 1 -- this is gap value like a list UI
	local Template = TemplateTextLabel:Clone()
	Template.Parent = Frame
	Template.Position = UDim2.new(val, 0, 0, 0)
	Template.Text = v.Name
	val += 1
end

Try this, if not working, try other script like above me.

image
Add value into 2.2 maybe, depends the size.

It works, but the position isn’t working. The text labels are in the same position

Nevermind I fixed it. I put the val variable at the top.

Andd I came across another problem.

Whenever a player joins late it will only add the text labels that joined after him

example:

lets say I joined.

and then my friend joined.

then 2 other friends joined.

My GUI would display everyone but my friends GUI would only display him and the 2 other friends.

Try listening for new players being added:

function PlayerAdded(player)
	local val = 1 -- this is gap value like a list UI
	local Template = TemplateTextLabel:Clone()
	Template.Parent = Frame
	Template.Position = UDim2.new(val, 0, 0, 0)
	Template.Text = v.Name
	val += 1
end

--players already in-game
for _, player in pairs(Players:GetPlayers()) do 
	PlayerAdded(player)
end
Players.PlayerAdded:Connect(PlayerAdded) --listening for new players

It didn’t work. It’s the same exact problem as before except that the labels are a randoms players name

local Players = game.Players

local TemplateTextLabel : TextLabel = script.TextLabel
-- Change this to your TextLabel that your own TextLabel design, Copy and Paste the TextLabel then put it to local script like this.

local Frame = script.Parent.Frame -- Change this to your Frame that has Player Value

local function refreshPlayers()
	spawn(function()
		for a,b in pairs(Frame:GetChildren()) do
			b:Destroy()
		end
		for i,v in pairs(Players:GetPlayers()) do
			local val = 1 -- this is gap value like a list UI
			local Template = TemplateTextLabel:Clone()
			Template.Parent = Frame
			Template.Position = UDim2.new(val, 0, 0, 0)
			Template.Text = v.Name
			val += 1
		end
	end)
end

Players.PlayerAdded:Connect(function()
	refreshPlayers()
end)

Players.PlayerRemoving:Connect(function()
	refreshPlayers()
end)

There I forgot to add the update function when like player is joined late.
Try this, if not working tell me the error from the Output/Developer Console.

I’m sorry, I don’t understand your question.

Do you want the text labels to be the name of each player in the game?

Or do you want the text labels to be the name of a players past usernames…