label.Text = plr.Name not working on SurfaceGui TextLabel?

Hi everyone! Currently making a sign thats supposed to change the text to the local player’s username, but it is not working for some reason. Here’s the code that’s supposed to change it. (Inside SurfaceGui’s TextLabel)

local label = script.Parent
local plr = game.Players.LocalPlayer

label.Text = plr.Name

When I run the game however, it does not work, and just keeps the text it was assigned to in the properties menu.
image

Am I missing something? I’m not too experienced with SurfaceGui’s. Any help is appreciated!

(No Output Errors by the way.)

You can’t run local scripts in the workspace, you have to move that script to StarterPlayerScripts, the change the path of the label variable,

Example (local script in StarterPlayerScripts):

local label = game.Workspace.Part.SurfaceGui.TextLabel
local plr = game.Players.LocalPlayer

label.Text = plr.Name
1 Like

Never knew that, thank you so much!

Yep, search Roblox local scripts on google, the first result should be from the Roblox DevHub. In that article, on top, you should see all the services that a local script can run (you got 5 or 6 options)

1 Like