I am trying to get the hunger and thirst to regen after the character dies and this is the only method I can think of to make this work.
function onPlayerEnter(player) local hunger = Instance.new("NumberValue") -- Creating the hunger value hunger.Name = "Hunger" hunger.Parent = player hunger.Value = 100 local thirst = Instance.new("NumberValue") -- Creating the thirst value thirst.Name = "Thirst" thirst.Parent = player thirst.Value = 100 while true do wait(2) hunger.Value = hunger.Value - 50 thirst.Value = thirst.Value - 50 if player.Character.Humanoid.Health <= 0 then -- Part that is not seeming to work. ): print("Working") wait(6) hunger.Value = 100 thirst.Value = 100 end while hunger.Value < 0 or thirst.Value < 0 do wait(0.5) player.Character.Humanoid.Health = player.Character.Humanoid.Health - 5 end end end game.Players.ChildAdded:connect(onPlayerEnter)
This is a bit of a workaround, but I'd put the Hunger and Thirst stat inside of the character model and put it in the character every time he respawns.
Also, this is my first post around here, so hi everyone. ^-^
Anyway, it would result in this code:
function onPlayerEnter(player) player.CharacterAdded:connect(function(character) local hunger = Instance.new("NumberValue") -- Creating the hunger value hunger.Name = "Hunger" hunger.Parent = player.Character hunger.Value = 100 local thirst = Instance.new("NumberValue") -- Creating the thirst value thirst.Name = "Thirst" thirst.Parent = player.Character thirst.Value = 100 while true do wait(2) hunger.Value = hunger.Value - 50 thirst.Value = thirst.Value - 50 --We don't require this anymore, player.CharacterAdded is also fired on respawn. -- if player.Character.Humanoid.Health <= 0 then -- Part that is not seeming to work. ): -- print("Working") -- wait(6) -- hunger.Value = 100 -- thirst.Value = 100 -- end while hunger.Value < 0 or thirst.Value < 0 do wait(0.5) player.Character.Humanoid.Health = player.Character.Humanoid.Health - 5 end end end) end game.Players.ChildAdded:connect(onPlayerEnter)