I have this hunger system, but when I die and the Value is like 40 it doesn't reset

When I join the game and I set the Value of Hunger to 40 or smth else below 100, when I die the Value doesn’t reset and it stays the same. When I die I want the Value to reset back to 100 and I have already tried it but it doesn’t work.
image


repeat wait() until Plr.Character

local Hum = Plr.Character:WaitForChild("Humanoid")
local MaxHunger = 100
local DecreaseRate = 40
local HungerValue

if Plr:FindFirstChild("HungerVal") then
    HungerValue = Plr.HungerVal
    HungerValue.Value = MaxHunger
else
    Instance.new("IntValue", Plr).Name = "HungerVal"
    Plr.HungerVal.Value = MaxHunger
    HungerValue = Plr.HungerVal
end

HungerValue.Changed:connect(function()
    wait()
    script.Parent.Hud.Hunger.UIGradient1.Offset = Vector2.new(0,-Plr.HungerVal.Value / 100)
    wait()
    script.Parent.Hud.Hunger.UIGradient2.Offset = Vector2.new(0,-Plr.HungerVal.Value / 100)
    wait()
    script.Parent.Hud.Hunger.UIGradient3.Offset = Vector2.new(0,-Plr.HungerVal.Value / 100)
    wait()
    if Plr.HungerVal.Value > 50 then
        script.Parent.Hud.Hunger.UIGradient1.Enabled = true
        script.Parent.Hud.Hunger.UIGradient2.Enabled = false
        script.Parent.Hud.Hunger.UIGradient3.Enabled = false
    end
    if Plr.HungerVal.Value <= 50 then
        script.Parent.Hud.Hunger.UIGradient1.Enabled = false
        script.Parent.Hud.Hunger.UIGradient2.Enabled = true
        script.Parent.Hud.Hunger.UIGradient3.Enabled = false
    end
    if Plr.HungerVal.Value <= 25 then
        script.Parent.Hud.Hunger.UIGradient1.Enabled = false
        script.Parent.Hud.Hunger.UIGradient2.Enabled = false
        script.Parent.Hud.Hunger.UIGradient3.Enabled = true
    end
    if Plr.HungerVal.Value >= 100 then
        Plr.HungerVal.Value = 100
    end

    if Hum.Health == 0 then
        Plr.HungerVal.Value = 100
    end

end)

while wait(DecreaseRate) do
    wait(DecreaseRate)
    HungerValue.Value = HungerValue.Value - 1

    if HungerValue.Value == 0 then
        repeat wait(1)
            Hum.Health = Hum.Health - 1000
        until HungerValue.Value > 0 or Hum.Health <= 0


    end
end

It could be that, at the beginning where it says if Plr:FindFirstChild(“HungerVal”) then.
Is the HungerVal a NumberValue? If so, then change HungerValue = Plr.HungerVal to HungerValue = Plr.HungerVal.Value.
Because if you want to change the value or get the value of a NumberValue, StringValue, etc, you should always use .Value.

It doesn’t work. The value is 0 all the time.

Actually the script that you see above was working perfectly, and today i went to test and it wasn’t reseting