Why won't my nametag script work? Please help!

Why are you trying to rename the text of the NameLabel inside the text label? You can just handle it via the script in ServerScriptService.

local players = game:GetService("Players")
local nametag = game:GetService("ServerStorage").BillboardGui

players.PlayerAdded:Connect(function(player)
     player.CharacterAdded:Connect(function(char)
	    local BillboardGUI = nametag:Clone()
	    BillboardGUI.Parent = char:FindFirstChild("Head")
        BillboardGUI.NameLabel.Text = player.Name
    end)
end)

That'sTheHead That’s the head. Sorry for the bad example.

Hey,
It worked but it broke my other label for some reason.

I will provide images in a minute.

Is there any error in the output and could I learn in which text label you are experiencing the issue?

@ProBaturay ,There are no errors in the output, it duplicated the billboard UI two times but I see my user in the back.
image

The script:

Try removing the first set of “PlayerAdded”, characterAddded event calls, because it seems you’re calling them twice, in your new script. Only needs to be setup once.

Should I remove the bottom ones?
I am getting an error when I do.

You are defining the same GUI twice as

local nametag = game:GetService("ServerStorage").BillboardGui

and

local BillboardGui = game.ServerStorage:WaitForChild("BillboardGui")

Are you sure there is 1 BillboardGUI or more? If it is more than 1 just change the name of the GUIs

My bad, there is only one billboardGui.

Hopefully this helps, but I would do the following: (you might even try commenting out the code instead of deleting it)

The top box is a different label then the first. Deleting it would break one of the labels.

:man_facepalming:t3: then try this

local players = game:GetService("Players")
local nametag = game:GetService("ServerStorage").BillboardGui

players.PlayerAdded:Connect(function(player)
     player.CharacterAdded:Connect(function(char)

        local leaderstats = player:WaitForChild("leaderstats")
        local timeAlive = leaderstats:WaitForChild("Time Alive")
	    local BillboardGUI = nametag:Clone()
	    BillboardGUI.Parent = char:FindFirstChild("Head")
        BillboardGUI.NameLabel.Text = player.Name
        BillboardGUI.TextLabel.Text = timeAlive.Value
        
        local humanoid = char:WaitForChild("Humanoid")
        humanoid:GetPropertyChangedSignal("Health"):Connect(function()
            BillboardGUI.HP.Text = humanoid.Health 
        end)
    end)
end)
1 Like

Oh I see, yeah try tinkering a bit see what works best. I think you’ll get this working pretty well, soon. I’ll probably try this out real quick, too. I do a similar thing for healthbars in my own game.

Your full revised script. Here you go.

1 Like

This namelabel worked but, the timer label stays at zero.
image

Really tried and new to code. Sorry for small slip ups in basic coding. (I just finished my finals a few hours ago). :frowning:

Try using tonumber in the line

BillboardGUI.TextLabel.Text = timeAlive.Value

to

BillboardGUI.TextLabel.Text = tonumber(timeAlive.Value)

You’re missing an event, you also need to parent it to the player’s head. You should also not put it into StarterCharacterScripts as it’s going to use excessive resources. You also have to let the server listen for things like .Died events and .CharacterAdded events.

This goes into ServerScriptService:

local serverStorage = game:GetService('ServerStorage') -- service we need
local players = game:GetService('Players')

local myBillboardGui = serverStorage:WaitForChild('BillboardGui') -- look for the billboardGUI

local function createOverhead(character) -- this will require the character model and handle our changes to the humanoid
    local currentBillboardGui = myBillboardGui:Clone() -- clone the overhead
    myBillboardGui.Parent = character:WaitForChild('Head') -- parents it to the head
    local humanoid = character:WaitForChild('Humanoid') -- we need the humanoid for a few properties such as the health and maxhealth
    local hp = currentBillboardGui:WaitForChild('HP')
    local nameLabel = currentBillboardGui:WaitForChild('NameLabel')
    nameLabel.Text = character.Name -- could also be Humanoid.DisplayName if you're looking into using that instead
    local healthConnection = humanoid:GetPropertyChangedSignal('Health'):Connect(function()
        hp.Text = humanoid.Health..'/'..humanoid.MaxHealth -- updates the label
    end)
    local maxHealthConnection = humanoid:GetPropertyChangedSignal('MaxHealth'):Connect(function()
        hp.Text = humanoid.Health..'/'..humanoid.MaxHealth -- same as above
    end)
    humanoid.Died:Connect(function()
        healthConnection:Disconnect() -- disconnect our connections and destroy the billboard
        maxHealthConnection:Disconnect()
        currentBillboardGui:Destroy()
    end)
end

players.PlayerAdded:Connect(function(player) -- the player gets passed through this event
    local character = player.Character or player.CharacterAdded:Wait() -- sometimes the char spawns before the PlayerAdded event is fired, this is why we use or CharacterAdded:Wait(), in case the Character property of the player is nil.
    createOverhead(character) -- call the createOverhead function and ensure we pass the character
    player.CharacterAdded:Connect(createOverhead) -- when the player spawns, the CharacterAdded event is fired, the character is automatically passed to the function using the connection
end)

Hey @ProBaturay, I just tried It, still won’t work. :frowning:

local players = game:GetService("Players")
local nametag = game:GetService("ServerStorage").BillboardGui

players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(char)

		local leaderstats = player:WaitForChild("leaderstats")
		local timeAlive = leaderstats:WaitForChild("Time Alive")
		local BillboardGUI = nametag:Clone()
		BillboardGUI.Parent = char:FindFirstChild("Head")
		BillboardGUI.NameLabel.Text = player.Name
		BillboardGUI.TextLabel.Text = tonumber(timeAlive.Value)

		local humanoid = char:WaitForChild("Humanoid")
		humanoid:GetPropertyChangedSignal("Health"):Connect(function()
			BillboardGUI.HP.Text = humanoid.Health 
		end)
	end)
end)

I’m sure you need to use delay because it will be waiting for getting the Time Alive value. It will return the value 0 so just add wait(1)

wait(1)
BillboardGUI.TextLabel.Text = tonumber(timeAlive.Value)