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.
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”)
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”
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
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)
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.
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.
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)