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