I got this code sample from an article on Roblox developer:
here is the code, I basically copied everything perfectly- other than changing the size and position
local player = game.Players.LocalPlayer
local unitFrame = script.Parent
local healthBar = unitFrame.HealthBarContainer.HealthBar
player.CharacterAdded:Connect(function(character)
local humanoid = character:WaitForChild("Humanoid")
humanoid.HealthChanged:Connect(function(health)
local healthPercentage = health / character.Humanoid.MaxHealth
healthBar.Size = UDim2.new(healthPercentage, 0, 1, 0)
end)
end)
I'm thinking maybe this is outdated? what should I change?

4 comments
Wouldn't it be local healthPercentage = character.Humanoid.MaxHealth - health
no that would be how much health is remaining. If i have 50% of my health left I want 50% of the bar to be filled, which is what divide currentHealth by maxHealth does
Use this for reference point to: https://developer.roblox.com/en-us/api-reference/event/Humanoid/HealthChanged I think this will help you.
what exactly is the problem here? is it that the bar doesnt move, is it a problem in what direction it moves in, etc.