Health Regeneration script not working

I’m not very experienced with coding, but what I wanted to do was make my Health Regen script wait about 7 seconds and then heal rapidly.

The problem is that I can lose health, but I can’t regenerate health at all. I would take fall damage and wait the seconds I put in, but nothing would happen afterwards. If there’s anything I did wrong in the script, please tell me.


local character = game.Players.LocalPlayer.Character
local Humanoid = character:WaitForChild("Humanoid")
local maxhp = Humanoid.MaxHealth

Humanoid.HealthChanged:Connect(function()
	print("health Changed")
	wait(7)
	print("healing")
	repeat
		Humanoid.Health = Humanoid.Health + 5
		wait(0.5)
	until hp >= maxhp
end)

In the script on line 12 I believe you mention something called hp. However nowhere in the script does it show you defined something called hp. Consider also changing maxhp to 100 instead of getting the MaxHealth number.

2 Likes

Would this work for the hp?

local hp = Humanoid.Health	

Yes I believe so. Don’t forget to check for output errors aswell.

Where do you have that code? Inside or outside of the HealthChanged?

local character = game.Players.LocalPlayer.Character
local Humanoid = character:WaitForChild("Humanoid")
local maxhp = Humanoid.MaxHealth

Humanoid:GetPropertyChangedSignal("Health"):Connect(function()
	print("Health changed")
	task.delay(7, function()
		print("healing")
		while Humanoid.Health < maxhp do
			task.wait(0.5)
			Humanoid.Health += 5
		end
	end)
end)

Instead of saying HealthChanged say

Humanoid:GetPropertyChangedSignal("Health"):Connect(function()
:+1:

I have it inside of HealthChanged.

I put in this script, and I was able to regenerate health. The only problems now are that it won’t heal the amount I put in and it won’t wait the 7 seconds either.

I recently found another post that talked all about a customizable health script and how to set it up. It helped with my problem, and I recommend it to anyone else with the same problem.
https://devforum.roblox.com/t/custom-health-regeneration-script/1927396

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