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

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.

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 — 9y
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 — 9y
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 — 9y
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 — 9y

1 answer

Log in to vote
1
Answered by 9 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:

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)
Ad

Answer this question