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

Why isnt this player.Name script working? NOT ANSWERED

Asked by
TrollD3 105
9 years ago

I made a script yesterday and today I fixed up so it should work but its still doesn't. I want to have the player's name show up in a textlabel. I have 16 players (max) in the game so that would mean 16 textlabels. Would I have to put this script inside each one (of course the name of the txtlabel would be different)?

To sum up : How do I get the player's name to show and Would I put this into 16 different txt labels?

script :

game.Players.PlayerAdded:connect(function(player)

for _, player in pairs(game.Players:GetPlayers()) do
game.StarterGui.MainGui.MenuButton.Lobby["Player1" .. game.Players.NumPlayers].Text = player.Name
end

end)
0
What is this script supposed to do, and what's wrong with it? We need this information to help you get a relevant answer. yumtaste 476 — 9y
0
I fixed it just in case people didnt understand. TrollD3 105 — 9y

2 answers

Log in to vote
0
Answered by
SurVur 86
9 years ago

This is a common mistake. You are changing the GUI inside StarterGui, you want to change the GUI inside of the playerGui (I hope).

game.Players.PlayerAdded:connect(function(player)

for _, player in pairs(game.Players:GetPlayers()) do
player.PlayerGui:WaitForChild("MainGui"):WaitForChild("MenuButton"):WaitForChild("Lobby")["Player1" .. game.Players.NumPlayers].Text = player.Name
end

end)

I have added plenty of WaitForChild()s, as well. If you are using FE, then this will be completely different.

0
still not working TrollD3 105 — 9y
Ad
Log in to vote
0
Answered by 9 years ago

There are some problems with your design. ex What happens if 2+ players leave, followed by someone else joining? You will potentially overwrite the TextLabel for someone who is still in the game.

Instead, do this:

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)

Now each label is guaranteed to hold the name of a player in the game (or be an empty string).

0
I just tried this and it doesnt work. Btw The textlabel isnt called lobby. The frame is called that and there are 16 txt labels under that. TrollD3 105 — 9y
0
Are your TextLabels called "Player11", "Player12", "Player13", etc (for players 1-3; ex player 12 would use TextLabel named "Player112"), or "Player1", "Player2", "Player3", etc? (Your script suggests the former, but I guessed the latter). What exactly doesn't work? Is there an error? Also, the "lobby" variable refers to your Lobby frame. This refers to the text label: lobby["Player" .. i] chess123mate 5873 — 9y
0
I fixed it to what you said and it still doesnt work. Also How would lobby display text if its not a text label? TrollD3 105 — 9y

Answer this question