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

How To Display Player Username On TextLabel?

I'm trying to display a players username on TextLable in ScreenGUI but...

I've tried many scripts including this one:

local player = game.Players.LocalPlayer game.StarterGui.YourHealthBar.Frame.TextLabel.Text = print(player)

and tried looking up the answers to other people that have asked the same question but I still couldn't get it to work.

2 answers

✓ Accepted answer

Hello. :}

Okay, well, first off, print("Hello world!") is used to print out things in the console (usually to find bugs in your code). You cannot set the text of the TextLabel to a console output using print.

As with all things in the game, they have a name. To get the name, which is a string value, you would use something like this:

local player = game.Players.LocalPlayer
local name = player.Name

Simple, right? So, to change the name of the text, you would use this code:

local player = game.Players.LocalPlayer
game.StarterGui.YourHealthBar.Frame.TextLabel.Text = player.Name

Hope this helped. :}

local player = game.Players.LocalPlayer
local sg = Instance.new("ScreenGui", player.PlayerGui)
local textLabel = Instance.new("TextLabel", sg)
textLabel.Text = player.Name

1 comment

0

Has to be a localscript though

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