Value Doesn't Change

Hi! I am trying to make a hunger script which will decrease the player’s hunger and make the player take damage, it seems however that the number value doesn’t change.
My script:

local timewait = 3 
local decreaseby = 1 
local player = game.Players.LocalPlayer 
local hum = player.Character 
local hunger = script.Parent.Hunger.Value


while true do
	wait(timewait)
	if hunger == 0 then
		hum.Health = 0
	else
		hunger.Value = hunger.Value -1
		game.Players.LocalPlayer.PlayerGui.Hunger.TextLabel = hunger
	end
end

You defined hunger as scipt.Parent.Hunger.Value and you put .Value again when calling the variable. You should replace hunger.Value = hunger.Value - 1 with hunger = hunger - 1. And also if you are changing leaderstats value, you cannot do that from a Local Script.

1 Like

Yes of course.
@BPilot253 is absolutely right!

You have already written

and again told it over here -

Here the solutions ! :

local timewait = 3
local decreaseby = 1
local player = game.Players.LocalPlayer
local hum = player.Character
local hunger = script.Parent.Hunger.Value

while true do
wait(timewait)
if hunger == 0 then
hum.Health = 0
else
hunger.Value = hunger.Value -1
game.Players.LocalPlayer.PlayerGui.Hunger.TextLabel.Text = hunger
end
end

Oh and put this script in server script service as a ServerScript.

I’ve changed it, the script still doesn’t work though.
My studio hierarchy:
image

You cannot put this in a Server Script since game.Players.LocalPlayer is only for valid for Local Scripts.

Why don’t you instead put a value inside the player and control it by firing a remote event to the server and changing from a server script?