Trouble On Making A Custom Healthbar Overhead Gui

  1. What do you want to achieve? Keep it simple and clear!
    I want to make a custom healthbar overhead gui.

  2. What is the issue? Include screenshots / videos if possible!
    The problem is that the health bar doesn’t change.

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I tried making it from tutorials but again it didn’t work or I’m doing something wrong.

This is the server script that I’ve put in StarterCharacterScripts.

local char = script.Parent
local hum = char:FindFirstChild("Humanoid")
local healthgui = script.BillboardGui
local filler = healthgui.Background.Filler
local tweenservice = game:GetService("TweenService")
healthgui.Adornee = char.Head

local Health = hum.Health
local MaxHealth = hum.MaxHealth

local percentage = Health/MaxHealth

local function HealthChanged()
	filler:TweenSize(UDim2.new(percentage, 0, 1, 0), "In", "Linear", 1)
end

hum:GetPropertyChangedSignal("Health"):Connect(HealthChanged)

You need to also include the calculations in the function, try this:

local char = script.Parent
local hum = char:FindFirstChild("Humanoid")
local healthgui = script.BillboardGui
local filler = healthgui.Background.Filler
local tweenservice = game:GetService("TweenService")
healthgui.Adornee = char.Head

local function HealthChanged()
    local Health = hum.Health
    local MaxHealth = hum.MaxHealth

    local percentage = Health/MaxHealth

	filler:TweenSize(UDim2.new(percentage, 0, 1, 0), Enum.EasingDirection.In, Enum.EasingStyle.Linear, 1)
end

hum:GetPropertyChangedSignal("Health"):Connect(HealthChanged)
1 Like