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

How To Display Player Username On TextLabel?

Asked by 7 years ago

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

Log in to vote
0
Answered by 7 years ago

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. :}

Ad
Log in to vote
0
Answered by
blowup999 659 Moderation Voter
7 years ago
local player = game.Players.LocalPlayer
local sg = Instance.new("ScreenGui", player.PlayerGui)
local textLabel = Instance.new("TextLabel", sg)
textLabel.Text = player.Name
0
Has to be a localscript though blowup999 659 — 7y

Answer this question