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