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

How do I get the name of a player?

Asked by 6 years ago

I've looked through all of the posts that have "name" in it but I can't seem to find anything that works. I'm trying to make a script that shows the name of the player and put it on a text label. Any way to go about doing it? Cheers.

0
If you post the code you have I would be more than willing to help :) 4d61736f6e 59 — 6y

4 answers

Log in to vote
0
Answered by
mattscy 3725 Moderation Voter Community Moderator
6 years ago

Every object in roblox has a .Name property, which will give you a string of the object's name. Text labels have a .Text property that can take a string and show it on the label. If you had a LocalScript inside of the text label, you could get the player who "owns" the text label through LocalPlayer and set the text to their name:

script.Parent.Text = game.Players.LocalPlayer.Name
0
Thanks! Xenevious 19 — 6y
0
But what if you wanted to say a message then the players name? 0311ntth 0 — 3y
Ad
Log in to vote
0
Answered by
Zafirua 1348 Badge of Merit Moderation Voter
6 years ago
Edited 6 years ago

Since it is fairly simple, I will post a quick example of it

-- [Declaration Section]
local Player = game:GetService("Players").LocalPlayer;
local PlayerName = Player.Name;
local PlayerGui = Player:WaitForChild("PlayerGui");

-- //TextLabel Location 
local ScreenGui = PlayerGui:WaitForChild("ScreenGui");
local TextLabel = ScreenGui:WaitForChild("TextLabel");

-- [Output Section]
TextLabel.Text = PlayerName;

Explanation

The following script is a LocalScript. First we are declaring the Local Player. Then we are getting its name through Player.Name. Name is a roblox identifier which essentially gives us the Name of the object we are referencing it to.

Since in our case we want the Name of the Local Player, we are going to do Player.Name. Then we implement the Name in the TextLabel. We do the following by adding TextLabel.Text = PlayerName.

Should you have any questions, feel free to comment below.

0
A question is where do we put the local script, I cant really understand. O_OIMGONE 9 — 4y
0
anywhere actually but the best place to put it is in StarterCharacterscripts CretuoX 0 — 4y
Log in to vote
0
Answered by 6 years ago

Hello, to get a name of a player is actually quite simple.


script.Parent.Mouse1Down:connect(function(player) --Not sure what you wanted so I'm just setting the text to whoever presses a text button local gui = player.PlayerGui.ScreenGui --gets the gui gui.TextLabel.Text = player.Name --Sets the text to the players name end)
Log in to vote
0
Answered by
zblox164 531 Moderation Voter
6 years ago
Edited 6 years ago

The simplest way would be this:

local Player = game.Players.LocalPlayer
local TextLabel = script.Parent -- Put the location of the label here

TextLabel.Text = Player.Name

Make sure your using a LocalScript for this since each player has a different name and your dealing with GUI elements.

Answer this question