(my other question got deleted and idk why...) Chess123mate edited my script and this is what he did. Why isnt this working? The script is supposed to get each player's name inside a text label. It doesnt say anything in output and the player names arent shown.
local lobby = game.StarterGui.MainGui.MenuButton.Lobby game.Players.PlayerAdded:connect(function(player) local ch = game.Players:GetPlayers() for i = 1, #ch do lobby["Player" .. i].Text = ch[i].Name end for i = #ch + 1, 16 do --clear the unused TextLabels lobby["Player" .. i].Text = "" end end)
btw the script is inside the textlabel = startergui.mainGui.menuButton.Lobby.Player(txtbutton).PlayerName(txtlabel) I have 16 txt buttons and 16 text labels to show the names of players in the game.
PlayerAdded doesn't work for LocalScripts, you have to use ChildAdded instead (see Players).
I'm going to assume that you want the name in the "PlayerName" TextLabel instead of the TextButton (with the TextButton's Text staying at "").
Corrected script:
local lobby = game.StarterGui.MainGui.MenuButton.Lobby game.Players.ChildAdded:connect(function(player) local ch = game.Players:GetPlayers() for i = 1, #ch do lobby["Player" .. i].PlayerName.Text = ch[i].Name end for i = #ch + 1, 16 do --clear the unused TextLabels lobby["Player" .. i].PlayerName.Text = "" end end)