bot=script.Parent Humanoid=bot:FindFirstChild("\072\117\109\097\110\111\105\100")local o=false function regenerate()if o then return end o=true while Humanoid.Health<Humanoid.MaxHealth do local o=wait(1)local W=Humanoid.Health if W>0 and W<Humanoid.MaxHealth then o=(.01*o)*Humanoid.MaxHealth W=W+o Humanoid.Health=math.min(W,Humanoid.MaxHealth)end end o=false end if Humanoid then Humanoid.HealthChanged:connect(regenerate)end

bot = script.Parent
Humanoid = bot:FindFirstChild("Humanoid")

local regen = false

function regenerate() 
	if regen then return end
	-- Lock this function until the regeneration to max health is complete by using a boolean toggle
	regen = true
	while Humanoid.Health < Humanoid.MaxHealth do
		local delta = wait(1)
		local health = Humanoid.Health
		if health > 0 and health < Humanoid.MaxHealth then 
			-- This delta is for regenerating 1% of max hp per second instead of 1 hp per second
			delta = 0.01 * delta * Humanoid.MaxHealth
			health = health + delta
			Humanoid.Health = math.min(health, Humanoid.MaxHealth)			
		end
	end	
	-- release the lock, since the health is at max now, and if the character loses health again
	-- it needs to start regenerating 
	regen = false
end	

if Humanoid then 
	-- Better than a while true do loop since it only fires when the health actually changes
	Humanoid.HealthChanged:connect(regenerate)	
end
