Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Can someone help me?

So I make a TextLabel then I put it in my screen GUI but I want the TextLabel to change to the name of the player but my script won't work. I'll show you what the script looks like, and if you could help that would be great.

while true do
wait()
script.Parent.Text = (script.Parent.Parent.Parent.Parent.Players.PlayerAdded.Name)

end 

3 answers

I don't know why you need a loop. Make sure you set player on line 1.

player = 
script.Parent.Text = player.Name

If you mean like an onJoin for each player that joins the server, then (Please use a LocalScript);

repeat wait(0)until game.Players.LocalPlayer --Will repeat waiting 0 seconds until player joins

game.Players.PlayerAdded:connect(function(plr) --Lets use the PlayerAdded event
script.Parent.Text = plr.Name --The Text is now showing the player who joined the game
end) --The end for the 'PlayerAdded' event

Or if you mean to show your Username in the box then;

repeat wait(0)until game.Players.LocalPlayer --Will repeat waiting 0 seconds until player joins
script.Parent.Text = game.Players.LocalPlayer.Name --The Text is now showing the player's name

Hope this helped!

Okay, so first of all there is no reason to put a loop. The players name should never change in the first place. If it does, you know that they are trying to exploit.

Also if you aren't already make sure you are using a localscript. Anything client-sided such as guis should always be handled by a localscript. It's bad coding practice to have a server script be inside the PlayerGui.

The last thing is if you are using a localscript then you have access to game.Players.LocalPlayer so you don't have to put script.Parent.Parent.Parent.Parent.

repeat wait(1) until game.Players.LocalPlayer -- wait for the localplayer to load
script.Parent.Text = game.Players.LocalPlayer.Name

Hope I helped

This discussion is preserved as it was. New answers, comments, and votes are closed.