Attempt to perform arithmetic (div) on nil and number

Hey! so im making a health bar script but im running into a problem, theres a strange error on the output saying: Players.TruckDriv3r.PlayerGui.MainHUD.LocalScript:50: attempt to perform arithmetic (div) on nil and number

Can anyone help me fix this?
Heres the script

game.Players.LocalPlayer.Character:WaitForChild("Humanoid"):GetPropertyChangedSignal("Health"):Connect(function(newh)
	local char = game.Players.LocalPlayer.Character
	local maxhealth = char.Humanoid.MaxHealth
	local bar = gui.Bars.HealthBar
	
	bar.Inner:TweenSize(UDim2.new(tonumber(newh)/tonumber(maxhealth), 0, 1, 0), Enum.EasingDirection.InOut, Enum.EasingStyle.Quart, 0.2, true)
end)

GetPropertyChangedSignal will not pass in the new health value into your function. You would need to define newh in that function, or use Humanoid.HealthChanged, since it does pass the new value of health.

Print the value for newh. It’s nil

Ohhh i didnt know about that health changed, i will try it, oh it worked! thanks for the help you two :slight_smile: