I've been working on a health regeneration script to work alongside the default roblox health regeneration script, but it works slightly differently, it only is active when the player's health is below 50%. It is pretty simple and is working completely fine, I just wanted to know if using Humanoid.HealthChanged is a problem considering that the function would fire whenever the health value changed, so it would fire not only when the player takes damage, but also when they are healed. I realized that the default health regen uses "while Humanoid.Health > 0 do" instead of using HealthChanged function, but as it is a loop which is always running for as long as the player is alive so I'm worried it may cause lag. Basically my question is which of those should I use? Which would be better perfomance-wise?
The one I'm currently using:
Humanoid.HealthChanged:Connect(function() if Humanoid.Health < Humanoid.MaxHealth / 2 and Active.Value == false then Active.Value = true while Humanoid.Health < Humanoid.MaxHealth / 2 do wait(RegenerationDelay) Humanoid.Health = Humanoid.Health + RegenerationRate end Active.Value = false end end)
The one I could use:
while Humanoid.Health > 0 do if Humanoid.Health < Humanoid.MaxHealth / 2 and Active.Value == false then Active.Value = true while Humanoid.Health < Humanoid.MaxHealth / 2 do wait(RegenerationDelay) Humanoid.Health = Humanoid.Health + RegenerationRate end Active.Value = false end end