Health Changing Script Not Working

I am attempting to make a script which heals a player 3 times faster when their health is below 25%

There are no errors in the output, I have tried print() at certain lines in the script. (Just after line 8, after line 9 and after line 13) but nothing printed.

Here is my script:

game.Players.PlayerAdded:Connect(function(plr)
	repeat wait() until plr.Character
	local char = plr.Character
	repeat wait() until char.Humanoid
	local h = char.Humanoid
	local qHealth = h.MaxHealth/4
	
	while h.Health <= qHealth do
		while true do
			plr.Character.Humanoid.Health = plr.Character.Humanoid.Health + 1
			wait(0.3)
		end
		plr.Character.Humanoid.HealthChanged:Wait()
	end
end)

I would appreciate any help, thanks.

1 Like
game.Players.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function(char)
		local Hum = char:WaitForChild("Humanoid")
	
		Hum.HealthChanged:Connect(function(h)
			if h <= 25 then
				repeat wait(1/3) Hum.Health = Hum.Health + 1 until Hum.Health >= 100
			end
		end)
    end)
end)

This is what i have got to, i have tested, and it seemed to work.

1 Like

In one of the while loops, you would want to break the loop when the Humanoid’s Health is 100 because you wouldn’t want to add up the Health when it is already on 100.

1 Like

I would reccomend using plr.CharacterAdded

game.Players.PlayerAdded:Connect(function(plr)
    plr.CharacterAdded:Connect(function(char)
	    local h = char:WaitForChild("Humanoid")
	    local qHealth = h.MaxHealth/4
	   
        h:GetPropertyChangedSignal("Health"):Connect(function() 
	        if h.Health <= qHealth then
		        while true do
			        h.Health = h.Health + 1
                    if h.Health >= 100 then
                        h.Health = 100
                        break
                    end
			        wait(0.3)
		        end
	        end
        end)
    end)
end)
3 Likes

It literally has the same function. you can even use .Changed

2 Likes

I have updated the code, might as well try it.

1 Like

Hi, it does seem to be working, but I am attempting that that heal speed stops at 1/4 of the players health.
I tried altering the script, but that didn’t seem to work.

game.Players.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function(char)
		local Hum = char:WaitForChild("Humanoid")
	
		Hum.HealthChanged:Connect(function(h)
			while h <= 25 do
				repeat wait(1/3) Hum.Health = Hum.Health + 1 until Hum.Health == 25
			end
		end)
    end)
end)
1 Like

I’am sort of trying to make a even better version of the script, you might have to wait a while…

And i will try to solve that.

2 Likes

Try this:

game.Players.PlayerAdded:Connect(function(plr)
    plr.CharacterAdded:Connect(function(char)
	    local h = char:WaitForChild("Humanoid")
	    local qHealth = h.MaxHealth/4
	   
        h:GetPropertyChangedSignal("Health"):Connect(function() 
	        if h.Health < qHealth then
		        while true do
			        h.Health = h.Health + 1
                    if h.Health >= qHealth then
                        h.Health = qHealth
                        break
                    end
			        wait(0.3)
		        end
	        end
        end)
    end)
end)

What happens is:

  1. It checks if the health has been changed
  2. If so, then it checks if the health is below 1/4 of the player’s max health (or 25)
  3. If so, then it sets off a while true loop which increases the player’s health by 1
  4. If the player’s health equal to or over 25, then it sets their health to 25 and breaks/stops the loop
4 Likes

Also, just a question, you would like it to be 3 times faster, or increase the health 3 times more?

1 Like