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

How do I receive a players name for a GUI?

Asked by
Ulysies 50
8 years ago

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

Log in to vote
0
Answered by
DeadToMe 105
8 years ago

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

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? Ulysies 50 — 8y
0
You don't need it in a function. DeadToMe 105 — 8y
0
Omg you are a genius. C; Ulysies 50 — 8y
Ad

Answer this question