LocalPlayer's name Text Label

Greetings!
I am sorry if this looks extremely easy but it’s almost 4 am and i really want to finish this.
Up to the point, i want so a Label’s text located in a part to change to the local player’s name.

For an example , if in a server there is player A and player B , the first one will see his name in the text label, while the player B will see his name.

Script used :

local playerservice = game:GetService("Players")
local player = playerservice.LocalPlayer

local Playertext = script.Parent

player.CharacterAdded:Connect(function()
	wait()
	Playertext.Text = player.Name
end)

Located in the part’s text label as a Local Script.

Thank you everyone for helping and understand.

2 Likes

Do u get any error in the output?

I checked the output every time i tried a new way to fix the problem, there was no error at all.

can u show us your explorer? Because I dont see a problem in ur code

It’s possible that the player’s character is being added before the LocalScript gets a chance to register it?

1 Like

Items in StarterGui gets added to PlayerGui after the character spawns so if you remove the CharacterAdded function it should work.

Define a function before character added, for example,

function PlayerAddedName()
   Playertext.Text = player.Name
end

player.CharacterAdded:Connect(PlayerAddedName())

I just wrote this in notepad so there’s probably some errors but you should get the gist

my guess is your problem is that the scripts not loading in enough time for the character to be added, so it won’t work in solo games, this should fix it

If you’re making the local script a descendant of the part, and the part is in Workspace, you will have to move the script because it only works under a few instances:


Source

I would put the local script in StarterPlayerScripts and then resolve its path to the label from Workspace. After that, your local script should be running correctly.

1 Like

Why do you have it connected to a .CharacterAdded? Wouldn’t it be easier to just do it once because it doesn’t seem like it changes later? Also you need to move the script to StarterPlayer because local scripts do not work in workspace.

The .CharacterAdded function seems redundant. Just replace the entire function with “Playertext.Text = player.Name” as it should be able to immediately detect the player + its name and then set the TextLabel’s Text to the name.

1 Like

Do the character added event in a server script and pass the character over in a remote event to a localscript.

The localscript can customize the characters viewed name.

You don’t need any events for this.
Here’s what you can do (in a LocalScript):

local Player = game:GetService('Players').LocalPlayer
local Label = script.Parent

Label.Text = Player.Name
2 Likes

Please read what OP is asking for instead of replying to solutions stating This is obvious.
While it may be obvious for you, it does not apply for everyone else on the DevForum.

Local Scripts don’t fire in Workspace, also the CharacterAdded event seems unnecessary.

It is not obvious. Being rude isn’t going to solve anything. Try and help him solve the problem instead of being incompetent.

Search for information before asking a question. It’s just common sense.

Yes, but why give him a hard time?

You could just either answer his question or link him to a DevHub page.

You are right, I am sorry.I just get really enraged when someone asks a question before researching XD

Tried with and without it and got the same results.

I tried thata step by step and got the same results

Well that worked, thank you for the advice!

If somebody will have the same issue, here is the last form that works thanks to @Tybearic

Thank you everyone! :heart:

4 Likes