Why isnt this script not adding health?

This script is meant to add a random amount of health every 5 seconds, but its not working.

There is no error in the output.

Code :



	while true do
		wait(5)
	local random = math.random(1, script.Parent.Humanoid.MaxHealth)
	print(random)
	script.Parent:FindFirstChild('Humanoid').Health = script.Parent.Humanoid.Health + random
	
	end

It prints the number, just dosent add the HP.

The health cannot exceed the max health. Try setting the health to 1 in the beginning and see if it starts increasing.

1 Like

It doesn’t exceed the max health, I did that and it still doesn’t increase.

If you do :TakeDamage() with a negative number, it adds it.

wait(3)
script.Parent.Humanoid.MaxHealth = 1000
script.Parent.Humanoid.Health = 1

while true do
    wait(5)
    local oldhealth = script.Parent.Humanoid.Health
	local random = math.random(1, script.Parent.Humanoid.MaxHealth/10)
	print(random)
	script.Parent:FindFirstChild('Humanoid'):TakeDamage(random * -1)
	print(old health.." was changed to: "..script.Parent.Humanoid.Health)
end
1 Like

Thanks so much! :smiley: This worked!

1 Like

Glad to hear it!! Let me know if you need any other help :slight_smile: .

1 Like