NumberValue Limit 0-100

So I wanted to make a hunger system for my game, and when I tried to limit the value to 0-100 it didn’t work
Here’s the script

game.Players.PlayerAdded:connect(function(player)
	hunger = Instance.new("IntValue", player)
	hunger.Name = "Hunger"
	hunger.Value = 100
end)

hunger.Value.Changed:Connect(function()
	if hunger.Value > 100 then
		hunger.Value = 100
	end
end)

I’m not sure why its not working, when I set the value over 100 it doesn’t change.
Also sorry if its something dumb and easy, I am not the best at scripting.

1 Like

Try this

game.Players.PlayerAdded:connect(function(player)
	hunger = Instance.new("IntValue", player)
	hunger.Name = "Hunger"
	hunger.Value = 100


   hunger.Changed:Connect(function()
	   if hunger.Value > 100 then
		   hunger.Value = 100
	   end
   end)

end)

try changing this

hunger.Value.Changed:Connect(function()

to

hunger.Changed:Connect(function()