Name Tag does not say players name

This is the script:

local Plr = game.Players.LocalPlayer
local Name = Plr.Name
local Tag = script.Parent

local TagText = Tag.SurfaceGui.Name

Plr.CharacterAdded:Connect(function()
	while true do
	wait(1)
	
	TagText.Text = Name
	end
end)

And it does not change the name tag’s text at all, the name tag itself is in a “Starter Character” model which I have put into Starter player, it is a local script. I also get no errors.

3 Likes

I made something like this, are you looking for a nametag on a part of the players body?

2 Likes

local TagText = Tag.SurfaceGui.Name
rename the name part to something else
It thinks you are getting the Name of the surface gui, not the instance called name
You can also change it to:

local TagText = Tag.SurfaceGui:FindFirstChild(“Name”)

3 Likes

To improve this, you can just try it in serverscript
This is the script:

game:GetService("Players"):PlayerAdded:Connect(function(plr)
local Name = plr.Name
local ui = game:GetService("ReplicatedStorage").SurfaceGui:Clone()
local TextLabel = ui.PlayerName

game:GetService("Players"):CharacterAdded:Connect(function(character)
ui.Parent = character.NameTag

	game:GetService("RunService"):Heartbeat:Connect(function()
		TextLabel.Text = Name
	end)
end)
end)

(you can ask me if you want to optimize it with local script)

  • this is written by mobile and it may have some errors
  • as lucky said the text label name in script.Parent.SurfaceGui.Name needs to be specific name as “TextLabel” not “Name”
4 Likes

OH, I see why it doesn’t work! You are doing local TagText = Tag.SurfaceGui.Name, this is changing the name of the surface gui. The textlabel inside the surface gui can not be named “Name”, otherwise roblox will think you are changing the name of the surface gui. Change the name of the textlabel that shows the players name to something else than name.

Example:

local TagText = script.Parent.SurfaceGui.PlayerName
3 Likes

I did that but it is still the default name, it wont change.

local Plr = game.Players.LocalPlayer
local Name = Plr.Name
local Tag = script.Parent

local TagText = script.Parent.SurfaceGui.PlayerName

Plr.CharacterAdded:Connect(function()
	while true do
	wait(1)
	
	TagText.Text = Name
	end
end)
3 Likes

You really should be doing this in ServerScriptService, can you show me what the explorer looks like for this.

3 Likes

2 Likes

Is the nametag part visible in workspace?

2 Likes

Well, not while coding and whatever, but when I play the game the player model is in workspace, and since the player model has the nametag, it is in workspace while playing.

1 Like


Here is an image of what I’m using for my game, is what you want it to look like?

1 Like

Yes, and no. I want it to be on a little part, like this:

(Jhon is the default name)

1 Like

Ah, I see I can fix this, first does the nametag part stick to the player? Make sure the FRONT of the part is facing outwards and not towards the torso. I will show you how to code it.

1 Like

@deathwish128000 put this script as server script in serverscriptservice and put surface ui in replicated storage

The name tag is in the starter model, here is a picture of workspace while playing:

Ok, I got it to work, I will paste the code in a minute.

there is should be a conflict between your variable “Name” and the property on an instance “Name”

image
Here’s what it looks like, is this correct? The text is blurry because of scaling but you can fix that.

That is what I want! How did you do it?

This code goes inside the server script inside ServerScriptService.

local players = game:GetService('Players')


players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(char)
		local nametagClone = script.SurfaceGui:Clone() --I have the surface gui inside of this script.
		nametagClone.Parent = char:FindFirstChild("Nametag") --Change Nametag to the name of the part inside the player charater.
		nametagClone.PlayerName.Text = player.Name
		
	end)
end)

Images to explain.
image

image

Make sure the size for the textlabel is 1,0,1,0

1 Like