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
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
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)
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.