Max Health GUI not updating

Im currently trying to make a UI which shows the local players health, atm I have a health stat system in place which changes my health upon me joining, when that happens my bar goes way out of frame and then comes back only after I get damaged, I made a hit block script as an example https://gyazo.com/c38b854db4bb15557f55d24731d0129d

Heres my local script:

local player = game.Players.LocalPlayer 
local char = player.Character or player.CharacterAdded:Wait()
local humanoid = char:WaitForChild("Humanoid")
local healthGui = script.Parent
local MaxHealth = humanoid.MaxHealth



humanoid:GetPropertyChangedSignal("MaxHealth"):Connect(function()
	MaxHealth = humanoid.MaxHealth
	local healthChange = humanoid.Health/MaxHealth
	healthGui.HealthBar:TweenSize(UDim2.new(healthChange * 0.4,0,0.025,0),"In","Linear",1)
	
end)
humanoid:GetPropertyChangedSignal("Health"):Connect(function()
	MaxHealth = humanoid.MaxHealth
	
	local healthChange = humanoid.Health/MaxHealth
	healthGui.HealthBar:TweenSize(UDim2.new(healthChange * 0.4,0,0.025,0),"In","Linear",1)
	
end)



why

Try my code, with my experience its not possible to have Direct Values in a Variable.

local player = game.Players.LocalPlayer 
local char = player.Character
local humanoid = char:WaitForChild("Humanoid")
local healthGui = script.Parent

humanoid.Changed:Connect(function()
    healthGui.HealthBar:TweenSize(UDim2.new(humanoid.Health/humanoid.MaxHealth,0,0.025,0),"In","Linear",1)
end)

Update the health even before the health cahnges:

local player = game.Players.LocalPlayer 
local char = player.Character or player.CharacterAdded:Wait()
local humanoid = char:WaitForChild("Humanoid")
local healthGui = script.Parent
local MaxHealth = humanoid.MaxHealth

humanoid:GetPropertyChangedSignal("MaxHealth"):Connect(function()
	MaxHealth = humanoid.MaxHealth
	local healthChange = humanoid.Health/MaxHealth
	healthGui.HealthBar:TweenSize(UDim2.new(healthChange * 0.4,0,0.025,0),"In","Linear",1)
end)
humanoid:GetPropertyChangedSignal("Health"):Connect(function()
	MaxHealth = humanoid.MaxHealth
	local healthChange = humanoid.Health/MaxHealth
	healthGui.HealthBar:TweenSize(UDim2.new(healthChange * 0.4,0,0.025,0),"In","Linear",1)
end)

healthGui:WaitForChild("HealthBar").Size = UDim2.new(healthChange * 0.4,0,0.025,0) -- This line
1 Like