Trying to regenerate a NumberValue's value

I’ve been trying to make a value regenerate itself back to its original number whenever its number is reduced. However, the script I have made, located inside the NumberValue instance, simply doesn’t do anything. No output errors, nothing.

local stamina = script.Parent
local number = stamina.Value

while true do
	wait(0.05)
	while stamina.Value < number do
		stamina.Value = stamina.Value + 2
		wait(0.05)
	end
end

I wrote this after taking notes from the script Roblox uses to regenerate health from avatars. I would like to know what I’m doing wrong and how I can make it work.

3 Likes

As it turns out, the actual issue was that changing the value through Studio didn’t trigger the regen script. An odd cause, but if I change the value through a script, it works.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.