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

How do I receive a players name for a GUI?

So I have asked this before, and the results were disappointing. I have screengui, with with a frame inside of it, inside that frame is the script, and a textlabel, inside the textlabel are 2 more textlabels(Not necessary for this question). I am trying to have the GUI say the players name the whole time they are on, and only they can see it. Well I have only gotten as far as..

function onPlayerEntered(player)
script.Parent.PName.Text = player.Name	
end

game.Players.PlayerAdded:connect(onPlayerEntered)

Some have told me that I needed it to wait until the player was entered..

function onPlayerEntered(player)

repeat wait() until player.Character
script.Parent.PName.Text = player.name
end

game.Players.PlayerAdded:connect(onPlayerEntered)

Others have said that name is not a property of player..

function onPlayerEntered(player)

local name = player.Character.Name
repeat wait() until player.Character
script.Parent.PName.Text = name
end

game.Players.PlayerAdded:connect(onPlayerEntered)

I am so lost, because these all seem like valid reasons but they don't work..

1 answer

✓ Accepted answer

First, Name is a property of Player.

If you're using ScreenGui, you can use a LocalScript to get the LocalPlayer, and thus, their name.

name = game.Players.LocalPlayer.Name

3 comments

0

Could you give me an example? I but the last code in a local script and replaced the name line with the line you said. But is does not work?

0

You don't need it in a function.

0

Omg you are a genius. C;

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