How do I set text to a players name?

Hello,
I’m trying to set this text to the local player’s name via a local script, however, the text GUI doesn’t seem to be updating! Any help is appreciated.

The script:

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

Players.PlayerAdded:Connect(function()
	player.CharacterAdded:Connect(function(Character)
		-- Sets welcome text
		script.Parent.Main.Welcome.Text = "Welcome,".. player.Name .."!"
	end)
end)
1 Like

You can try ´

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




while wait(.1) do
Players.PlayerAdded:Connect(function()
	player.CharacterAdded:Connect(function(Character)
		-- Sets welcome text
		script.Parent.Main.Welcome.Text = "Welcome,".. player.Character.Name .."!"
	end)
     end)
end

I’m pretty sure that game.Players.PlayerAdded only works server-side. My recommendation is to do this using remote events, or just setting the text with a script.

2 Likes

Still didn’t work! I’m not too sure why it’s not working.

1 Like

I never knew it was only server-side i’ll try using a remote event! :slight_smile:

1 Like

Also, your code has it so that when any player joins the game and loads their character, it says “Welcome, [localPlayer]” when any player joins, since you didn’t create a parameter for the newly joining player.

1 Like

This code will not work, and if it did, it would continuously create PlayerAdded connections, basically repeating the function multiple times.

1 Like

If this is all that’s in the script, you can always just put this into StarterCharacterScripts and keep it as a local script like so:

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

script.Parent.Main.Welcome.Text = "Welcome,".. player.Name .."!"
1 Like

This doesn’t seem to work either!

Are there any errors showing up in the console?

Nope! I’m not too sure why the text won’t update which is why I came here.

Where is the gui that you’re trying to change the text of located at

It’s in the StarterGUI service.

So you’re saying that the Gui’s text is located in game.Players[player].PlayerGui.Main.Welcome.Text, so did you do this?

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

player.PlayerGui.Main.Welcome.Text = "Welcome," .. player.Name .. "!"

Correct?
And it’s a local script inside of StarterCharacterScripts

1 Like

No, the text is within the GUI which is within the starter GUI if that makes sense :smiley: .

Yes, I know. That’s why the path game.Players[player].PlayerGui.Main.Welcome.Text goes to PlayerGui, because when the game loads, everything from StarterGui is cloned into PlayerGui, so, start up your game and verify where the gui is and then if possible could you send a screenshot of where it’s located in your game?

The script xnSly wrote works perfectly fine. Make sure that the script is running in a localscript and not a normal script.