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 the player's name?

I know this is a dumb question, but ive tryed script after script and nothing seems to even slightly work. I'm stumped.. I've got a textlabel in a frame in a screengui, and I need it to say the player's name when they have entered the game and stay there, and all I know how to do is to tag the players name after they have said something in the chat..

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

game.Players.PlayerAdded:connect(onPlayerEntered)

I understand it doesn't explain who the player is but i'm confused what how to explain it.

3 answers

✓ Accepted answer

function onPlayerEntered(player)

script.Parent.PName.Text = player.Parent.Name

end

game.Players.PlayerAdded:connect(onPlayerEntered)

I hope this will help you. This is my first time answering a question here so idk if this is the way but you just needed to add "Parent" after player

1 comment

0

The parent of the "Player" instance is the "Players" instance. The name of the players parent is "Players", sorry ^^

function onPlayerEntered(player)
repeat wait() until player.Character
script.Parent.PName.Text = player.Name
end

game.Players.PlayerAdded:connect(onPlayerEntered)

There is no problem with this script, but are you sure that you placed the script inside the Frame? I still added something that is waiting for the Character to exist as the player perhaps has not loaded.

2 comments

0

It changed nothing..

0

Well, as I said. There's nothing wrong with this script.

There is no "Name" property inside a player. To get the name, you would have to get the name of the character object of the player. So to get the name of the player, do this:

local name = player.Character.Name

Hope this helped.

Your welcome.

2 comments

0

Sorry that didnt help..

0

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

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