if its in a player script it might stop working when it gets errored because it cant find the player Character's Humanoid
also, task.wait() is the improved version of wait() and is more accurate, while wait() is now deprecated
replace it with
local Player = game:GetService("Players")
while task.wait(0.1) do
if Player.LocalPlayer.Character then
if player.LocalPlayer.Character:FindFirstChild("Humanoid") then
local HP = Player.LocalPlayer.Character.Humanoid.Health / Player.LocalPlayer.Character.Humanoid.MaxHealth
script.Parent.Bar:TweenSize((UDIM2.new(HP, 0, 0.45, 0)), Enum.EasingDirection.Out, Enum.EasingStyle.Quad, 0.2)
end
end
end