Text won't change to LocalPlayer's Username but says it does

  1. What do you want to achieve?
    I would like to change a TextLabel’s text to the LocalPlayer’s username.

  2. What is the issue?
    The text will not change, but when printing the text’s value, the value is the LocalPlayer’s username.

  3. What solutions have you tried so far?
    I’ve tried many different things. I’ve tried to change the way the script get’s LocalPlayer, I’ve tried changing the variables, nothing has changed.

The code:

local frame = script.Parent.Frame.Frame
local plr = game.Players.LocalPlayer
local username = frame.Username.Text

print(plr)

username = plr
print(username)

The output prints “username” as the player’s username, but the text still doesn’t change.
image

Thanks to anyone who helps!

P.S.
This topic may be a duplicate, which I am sorry about, but I searched for many different queries and none of them gave me the answers I needed.
Also, I am, uh, quite a noob scripter in case you couldn’t tell, heheh.

Try username = plr.Name, but that should work

I’ve also never done it that way before (Putting .text in a variable), you can just delete the variables and cram it into 1 line if you aren’t going to use them later.

Problem here is that you’re setting the variable username to what Username.Text already is. Realize that username is not a reference that you can use to change the text. This concept applies to most things in roblox (tables excluded). For instance:

local a = 1
local b = a
print(b) -- Prints '1'
a = 5
print(b) -- Prints '1' despite a being changed

With this in mind, if you want to change a text value then you’ll have to assign to it specifically:

local frame = script.Parent.Frame.Frame
local plr = game.Players.LocalPlayer
frame.Username.Text = plr.Name 

Note that I changed it to plr.Name instead of just plr.