Player's name to Text GUI isn't working

I’ve made a script for a text label. What it’s supposed to do is collect the player’s name and put it on the text label. However, when I play the game, the name doesn’t appear.

Here’s the script:

game.Players.PlayerAdded:Connect(function(player)
	script.Parent.Text = player.Name
end)
1 Like

Hello, instead of that script, use this one:
script.Parent.Text = game.Players.LocalPlayer.Name
Let me know if it helped.

2 Likes

Your script is yielding before player added is called. Loop through a list of all of the players before you call player added.

1 Like

So how do you do it? Can you give me an example?

1 Like
for _, plr in pairs(players:GetPlayers()) do -- a "for" loop. 
   -- players:GetPlayers() returns a table with all the players in the game
   -- "plr" is the current player the loop in on

   -- code things here
end)

just an example

1 Like