Your current while loop has a condition of Thirst.Value >= 0, therefore making it break when the value of Thirst becomes -1 (which it does with its current setup).
A better approach is to create a new loop each time the player respawns. Using the CharacterAdded event, we can accomplish this. As for our while loop, we should set it's condition so that it breaks when the character dies (in other words humanoid.Health > 0).
Now we want one of two things to happen in the while loop. If the thirst value is greater, than zero then we want to decrement it by 1 every second. If the thirst value is anything else (<= 0), then we want the humanoid to take 5 damage every 10 seconds.
Complete Script:
game.Players.PlayerAdded:connect(function(player)
local Thirst = player.stats.Thirst
player.CharacterAdded:connect(function(character)
local humanoid = character:WaitForChild("Humanoid")
while humanoid.Health > 0 do
if Thirst.Value > 0 then
Thirst.Value = Thirst.Value - 1
wait(1)
else
humanoid:TakeDamage(5)
wait(10)
end
end
end)
end)
2 comments
put some prints around the script
SO. for some reason taking out my wait time fixed it but I don't understand why I didn't work without the wait time before... (you don't see the wait time in this post)