Healthbar billboardGUI

local player = game.Players.LocalPlayer
local Character player.Character or player.CharacterAdded:Wait()
local head Character: WaitForChild("Head") local healthGUI = game.StarterGui.BillboardGui:Clone()
local Humanoid - Character: WaitForChild("Humanoid")
game.Players.PlayerAdded: Connect(function()
healthGUI.Parent = head
healthGUI.Adornee = head
end)
Humanoid.HealthChanged: Connect(function()
healthGUI.Redfr.GreenFr.Size UDim2.new(Humanoid.health/Humanoid.MaxHealth, 0, 1, 0)
end)

So I want to make health counter over the head. But when I test billboardGUI stuck on workspace. Can anyone help pls?

1 Like
local player = game.Players.LocalPlayer
local Character = player.Character or player.CharacterAdded:Wait() --you need an equal sign to define a variable
local head  = Character: WaitForChild("Head") --you forgot an equal here
local healthGUI = game.StarterGui.BillboardGui:Clone() --I made it in its own line so that its more readable
local Humanoid = Character: WaitForChild("Humanoid") --the minus sign should of been an equal
--the playeradded event wont run if this player joins, it will run if another player joins because its a local script
healthGUI.Parent = head
healthGUI.Adornee = head

Humanoid.HealthChanged: Connect(function()
healthGUI.Redfr.GreenFr.Size = UDim2.new(Humanoid.Health/Humanoid.MaxHealth, 0, 1, 0) --you also forgot an equal here, also I made the 'h' in health captial, not sure if its required but I did just in case
end)

also put the local script in starter character scripts

1 Like

So he will appear on every player who join?

if you want it to appear to every player, make a normal script to server script service and put this in:

game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function()
local Character = player.Character
local head  = Character: WaitForChild("Head") 
local healthGUI = game.StarterGui.BillboardGui:Clone()
local Humanoid = Character: WaitForChild("Humanoid") 

healthGUI.Parent = head
healthGUI.Adornee = head

Humanoid.HealthChanged: Connect(function()
healthGUI.Redfr.GreenFr.Size = UDim2.new(Humanoid.Health/Humanoid.MaxHealth, 0, 1, 0) 
end)
end)
end)

also disable the local script if this one works so that the player doesnt have 2 guis stacked ontop of each other

1 Like

Ok thank you so much for helping

Hi @12312ababc. I have another problem hewlth changed is not working on server script

@12312ababc

game.Players.PlayerAdded:Connect(function(player) player.CharacterAdded:Connect(function()
  local Character = player.Character  
local head = Character:WaitForChild("Head")
  local healthGUI = game.Workspace.zyabka.BillboardGui:Clone()  
local playername = healthGUI.PLRName
  local Humanoid = Character: WaitForChild("Humanoid")  
healthGUI.Parent = head
  healthGUI.Adornee = head   Humanoid.HealthChanged:Connect(function()
    healthGUI.Redfr.GreenFr.Size = UDim2.new(Humanoid.Health/Humanoid.MaxHealth, 0, 1, 0)    
healthGUI.StudsOffset.Y = 3
   end)
playername.Text = player.Name
 end)
end)
game.Players.PlayerAdded:Connect(function(player) player.CharacterAdded:Connect(function()
  local Character = player.Character  
local head = Character:WaitForChild("Head")
  local healthGUI = game.Workspace.zyabka.BillboardGui:Clone()  
local playername = healthGUI.PLRName
  local Humanoid = Character: WaitForChild("Humanoid")  
healthGUI.Parent = head
  healthGUI.Adornee = head   Humanoid.HealthChanged:Connect(function()
    healthGUI.Redfr.GreenFr.Size = UDim2.new(Humanoid.Health/Humanoid.MaxHealth, 0, 1, 0)   
   end) 
healthGUI.StudsOffset = Vector3.new(0,3,0) --StudsOffset.Y is only a readable meaning you cant edit it, and you have to edit the studsoffset property with a vector3, also I moved it outside of the health changed event so that it runs even if the player's health doesnt change
playername.Text = player.Name
 end)
end)

Ok thank you so much for all helping

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.