Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Player script help?

Asked by
TrollD3 105
10 years ago

(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.

01local lobby = game.StarterGui.MainGui.MenuButton.Lobby
02game.Players.PlayerAdded:connect(function(player)
03    local ch = game.Players:GetPlayers()
04    for i = 1, #ch do
05        lobby["Player" .. i].Text = ch[i].Name
06    end
07    for i = #ch + 1, 16 do --clear the unused TextLabels
08        lobby["Player" .. i].Text = ""
09    end
10end)

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.

0
Why do you have a "Player" TextButton and a "PlayerName" TextLabel? Are the TextButtons named "Player1" through "Player16", or are they all named "Player"? chess123mate 5873 — 10y
0
They are named Players 1-16 and i have a text label inside the text button to make the gui text look better. TrollD3 105 — 10y
0
I am assuming that you want it so when a player joins, it'll create/change a textlabel inside of all of the players' guis that has that player's name on it. The best way to accomplish this is through remoteEvents SurVur 86 — 10y
0
Any solutions to the above question? Im not saying that the input wasnt good, but I really want to find out this script's problem TrollD3 105 — 10y

1 answer

Log in to vote
1
Answered by 10 years ago

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:

01local lobby = game.StarterGui.MainGui.MenuButton.Lobby
02game.Players.ChildAdded:connect(function(player)
03    local ch = game.Players:GetPlayers()
04    for i = 1, #ch do
05        lobby["Player" .. i].PlayerName.Text = ch[i].Name
06    end
07    for i = #ch + 1, 16 do --clear the unused TextLabels
08        lobby["Player" .. i].PlayerName.Text = ""
09    end
10end)
Ad

Answer this question