How to put a billboardGUI inside player's head once joined

So I’ve made a pretty cool billboard GUI which is also scripted and working correctly and I want to use it to replace the player’s normal healthbar, but I don’t know how do I make a script that puts that GUI inside the player’s character’s head when they just joined.
Does anyone know how to help?

-- GUI script
local frame = script.Parent
local meter = frame.Meter
local label = frame.Label

local character = frame.Parent.Parent.Parent
local humanoid = character:WaitForChild("Humanoid")

label.Text = humanoid.Health .. "/" .. humanoid.MaxHealth
meter.Size = UDim2.new(humanoid.Health / humanoid.MaxHealth, 0, 1, 0)

humanoid:GetPropertyChangedSignal("Health"):Connect(function()
	label.Text = humanoid.Health .. "/" .. humanoid.MaxHealth
	meter.Size = UDim2.new(humanoid.Health / humanoid.MaxHealth, 0, 1, 0)
end)

while true do
	if humanoid.Health == humanoid.MaxHealth then
		task.wait()
		frame.Visible = false
	else
		task.wait()
		frame.Visible = true
	end
end -- This while loop checks if the player's health is full, so if it is then it makes the bar invisible, but if it's not then it makes it visible

image
gui explorer


gui from server side

image
no damage

image
damaged

Insert Into ServerScriptService

local Players = game:GetService("Players")

local Gui -- Change with your gui

Players.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function(char)
		Gui:Clone().Parent = char
	end)
end)

This must be local script and then insert into gui your frame:

-- GUI script
local frame = script.Parent
local meter = frame.Meter
local label = frame.Label

local character = frame.Parent.Parent.Parent
local humanoid = character:WaitForChild("Humanoid")

label.Text = humanoid.Health .. "/" .. humanoid.MaxHealth
meter.Size = UDim2.new(humanoid.Health / humanoid.MaxHealth, 0, 1, 0)

humanoid:GetPropertyChangedSignal("Health"):Connect(function()
	label.Text = humanoid.Health .. "/" .. humanoid.MaxHealth
	meter.Size = UDim2.new(humanoid.Health / humanoid.MaxHealth, 0, 1, 0)
 
    if humanoid.Health == humanoid.MaxHealth then
		frame.Visible = false
	else
		frame.Visible = true
	end
end)
1 Like

use player.CharacterAdded Event then use its character parameter to find its head using WaitForChild() then parent gui to head

1 Like

Where should I put the GUI, keep it in a rig or somewhere else?

You can put inside of server script it should work and use:

local Gui = script.HealthBar

Yeah well that worked, but I’m now stuck with this

image

1 Like

Ok do you want it to move or something like that or stay in same place?

I want it to be moved, and I also assume the script inside the healthbar doesnt work because the whole bar doesnt disappear, nor it doesnt update (it’s saying 0/0 hp)

Local Script should be in frame and make BillboardGui’s Extense Size to :
0, 1.45, 0

No errors or anything in output by the way, just the “infinite yield possible on waitforchild humanoid”

The gui uses a normal SCRIPT, not a LOCALSCRIPT by the way, probably so others can see the hp bar too
image

image

1 Like

Now it updates, but it needs to be moved, probably the parent should be the head for it to work.

Also, how do I control the health regen? Like, I set health on my character to 50, and then he just started regenerating it and it went like 51.9348219034213842/100

1 Like

Use:

label.Text = math.floor(humanoid.Health .. "/" .. humanoid.MaxHealth)


:sob:

oh sorry:

local Health = math.floor(humanoid.Health)

label.Text = Health.. "/" .. humanoid.MaxHealth

Let’s get to that later because that just turned it into saying 100/100 even if it’s less than 100 hp, the main question is how do I assign the character’s head as parent of the GUI?

i changed the gui giver script to
Gui:Clone().Parent = char.Head
but it just says 0/0 now and doesnt disappear :sob:

1 Like

Ok change this in your other script

local character = frame.Parent.Parent
back to

local character = frame.Parent.Parent.Parent

Damn im blind sorry.

1 Like

It’s not a problem; I assume you’re writing on mobile, but I’m on PC, so my replies are faster.

1 Like

Still doesnt move it. Still stays in the body, and says 0/0