Can I update math.clamp function?

I’m currently trying to create a food system. I use local script to change the “food” value from player’s stats when any food is eaten.

local event = game.ReplicatedStorage.Food

local player = game.Players.LocalPlayer
local PlrStats = player:WaitForChild("Stats")
local food = PlrStats.Food

local function FoodEaten (energy)
	food.Value = energy
end
event.OnClientEvent:Connect(FoodEaten)

Then I have a script for math.clamp:

local event = game.ReplicatedStorage.Food

game.Players.PlayerAdded:Connect(function(plr)
	local plrStats = plr:WaitForChild("Stats")
	local food = plrStats.Food

	while wait(1) do
		food.Value = math.clamp(food.Value-1,0,1000) --ehkä vois vaihtaa tähän kaikkiin kohtiin plrStats.food tai jotaki?
	end
end)

When the player joins the food’s value starts counting down from 100. When the player clicks the food, the food value should change to 50 and continue counting down from that. The problemis that the food value remains 50 only for a second then the value jumps back to where ever it was left like nothing had ever changed.

If you have any idea what I could do, please help. Thank you.

Have you tried doing food.Value = 50 on whatever script that makes the food value to 50?