Edit: I put a local script inside starter character so that Humanoid updated with each new character. I am sure there is a more efficient way of doing this, but it works. The script was original inside the GUI

What can I do about this? When the player dies, the script no longer works because Humanoid is not connected to the new humanoid. I tried that Died function but it didn't fix anything.

local player = game:GetService("Players").LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local Humanoid = char:WaitForChild("Humanoid")

Humanoid.Died:Connect(function()
    char = player.Character or player.CharacterAdded:Wait()
    Humanoid = char:WaitForChild("Humanoid")
end)

local HealthNumber = script.Parent.Parent.Parent.Number
local Change = script.Parent

Humanoid.HealthChanged:Connect(function(newHP)
    local MaxHP = Humanoid.MaxHealth
    
    local percent = newHP/MaxHP * 100
    
    print(percent)
    
    Change:TweenSize(UDim2.new(percent/100,0,1,0), Enum.EasingDirection.In, Enum.EasingStyle.Linear, .1, true)
    script.Parent.Parent.Parent.Number.Text = newHP.." / "..Humanoid.MaxHealth
    
    if percent > 80 then
        Change.BackgroundColor3 = Color3.fromRGB(60, 255, 109)
    elseif percent < 80 and percent > 20 then
        Change.BackgroundColor3 = Color3.fromRGB(255, 202, 79)
    elseif percent < 80 and percent < 20 and newHP ~= 0 then
        Change.BackgroundColor3 = Color3.fromRGB(255, 55, 58)
    end
end)