Why does this thirst bar not work?

I have this thirst bar in StarterGUI with a script that controls it. When the player first spawns, it works fine. After they die, it doesn’t and the only error I get is this line: ThirstValue is not a valid member of Player "Players.asunoandkrito" I don’t know why it happens. Help?

Code:

local HG = script.Parent
local Text = HG:WaitForChild("Hydration"):WaitForChild("Text")
local Plr = game.Players.LocalPlayer

repeat wait() until Plr.Character

local Hum = Plr.Character:WaitForChild("Humanoid")
local MaxThirst = 19
local DecreaseRate = 8 -- the lower the number, the faster it decreases.  the higher the number, the longer it will take before decreasing
local ThirstValue

if Plr:FindFirstChild("ThirstVal") then
	ThirstValue = Plr.ThirstValue
	ThirstValue.Value = MaxThirst
else
	Instance.new("IntValue", Plr).Name = "ThirstVal"
	Plr.ThirstVal.Value = MaxThirst
	ThirstValue = Plr.ThirstVal 
end

ThirstValue.Changed:connect(function()
	Text:TweenSize(UDim2.new(ThirstValue.Value/MaxThirst,0, 0.55,0), "Out", "Linear", .5, true)
end)

while wait(DecreaseRate) do
	if ThirstValue.Value - 1 >= 0 then
		ThirstValue.Value = ThirstValue.Value - 1
	end
	
	if ThirstValue.Value == 0 then
		repeat wait(1)
			Hum.Health = Hum.Health - 2
		until ThirstValue.Value > 0 or Hum.Health <= 0
	end
end
1 Like
  1. You haven’t parented the First Value anywhere
  2. You’ve done ThirstVal and ThirstValue on 2 different lines.

NVM, I figured it out, ThirstValue is supposed to be ThirstVal, I spelt it wrong

Lol, have a good day and happy deving!