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.
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
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.
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)
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.