Player loses health when they become thirsty

I have a value called thirst that slowly goes down over time. When it hits 0 I want the player to start losing health. I am getting the following errors code. Anyone know the problem?

local statss = game.Players.LocalPlayer:WaitForChild("Stats")

local player = game.Players.LocalPlayer

if player[statss].Thirst.Value <= 0 then

player.Character.Humanoid.Health = player.Character.Humanoid.Health - 5

end

Hello!

Where exactly is your error?

I just get this error and nothing happenes.

Ok I’ve found the reasoning to your error!

What you’re doing is “player[statss]” that would be invalid as you already called it with the statss variable.
When you’re accessing a child in an object. If you do Instance[], This means that you’re indexing something in the object.

So you should try:

local statss = game.Players.LocalPlayer:WaitForChild("Stats")
local player = game.Players.LocalPlayer

if statss.Thirst.Value <= 0 then
	player.Character.Humanoid.Health = player.Character.Humanoid.Health - 5
end

If this doesn’t work please inform me of any other errors :herb:

local player = game:GetService("Players").LocalPlayer 
local statss = player:WaitForChild("Stats")
statss:WaitForChild("Thirst"):GetPropertyChangedSignal("Value"):Connect(function()
  if statss.Thirst.Value <= 0 then
    local char = player.Character or player.CharacterAdded:Wait()
    char.Humanoid.Health = 0 -- if you want to decrease it by 5: -= 5; or: = 0
  end
end)

@BlackFerocious is this working

I dont get any errors, but when my thirst gets low it dosent kill me. Currently I have the script as a local script in StarterPlayerScripts. Is that the problem.

Your script is programmed to remove health by 5 | -= 5

I’m not sure if you mean this, but if you want to kill the player you can do this:

player.Character.Humanoid.Health 0

Yea, Thats what I wanted.
(Not enough chars)

This works! Thank you for helping.