Custom health regeneration not working

Hi, I’ve been trying to get my own health regeneration script working, but nothing I do works. The normal health regeneration acts over it, while my script doesn’t work. I’ve tried things like removing the normal health regen, and firing remote events, but nothing I did worked. There aren’t any errors in the console either, so now I’m posting here. I hope this topic can help myself and other developers having the same issue

Here’s my script, in case the script is the issue:

(if you need the remoteevent version then I can reply with it. players can also increase their maximum health in-game, so that’s why i included numbers going to 200)

local hum = script.Parent.Humanoid

if hum.Health > 150 and hum.Health < 200 and hum.Health > 0 and hum.Health < hum.MaxHealth then
	repeat
		hum.Health = hum.Health + 1
		wait(8)
	until
	hum.Health < 120
end

if hum.Health > 120 and hum.Health < 150 and hum.Health > 0 and hum.Health < hum.MaxHealth then
	repeat
		hum.Health = hum.Health + 1
		wait(6)
	until
	hum.Health < 60 or hum.Health > 150
end

if hum.Health > 60 and hum.Health < 100 and hum.Health > 0 and hum.Health < hum.MaxHealth then
	repeat
		hum.Health = hum.Health + 1
		wait(5)
	until
	hum.Health < 20 or hum.Health > 60
end

if hum.Health > 20 and hum.Health < 60 and hum.Health > 0 and hum.Health < hum.MaxHealth then
	repeat
		hum.Health = hum.Health + 1
		wait(3)
	until
	hum.Health > 60 or hum.Health < 20
end

if hum.Health > 0 and hum.Health < 20 and hum.Health > 0 and hum.Health < hum.MaxHealth  then
	repeat
		hum.Health = hum.Health + 1
		wait(0.8)
	until
	hum.Health > 20
end

Thank you for considering to help me!

1 Like

Have you tried basic debugging? such as printing a string to make sure it is firing properly? i would also use => or =< in your script incase it is exactly on those intervals, please run basic diagnostics by debugging these factors and tell me how it goes, also try doing: print(hum.Health) and tell me what it gives back.

1 Like

Name the script Health and put it in Character scripts this should disable the default one

1 Like

This could be a factor, but also diagnosing the code using debugging I would highly suggest incase its an issue with in the code itself,

another factor could be they are using > < and not => =<, so if it is exactly on 20 or 60, something like that, the code won’t run.

1 Like

Agreed with @JS_CCoded
Also in the first if statement, why mention hum.Health > 150 and the after hum.Health < 200 a comparison of hum.Health > 0? Kinda redundant.

Try instead:

local Hum = Script.parent.Humanoid

if Hum.Health => 0 and Hum.Health =< 200 then
   repeat
      Hum.Health = Hum.Health + 1
      wait(8)
   until
   Hum.Health =< 120
end

And so on with the rest of the code blocks.

1 Like

Yo this code will only run once and will just do all the check when the player is at full health and then never check it again. You need to constantly check the health. Not just at the start. Pretty sure this is an issue

2 Likes

Okay, thank you everyone so much for replying. I managed to resolve the issue thanks to all your help. There’s a lot to respond to so I’ll make one big reply for everyone.

@JS_Coded

It was running properly, but the it only ran once since I didn’t put it in a loop. When I put it in a while true do loop, the prints appeared in the console. Also I kind of forgot the print command existed, I’ll be sure to use it from now on!

@Osrock_626

The if statements are supposed to have the health regeneration rate increase depending on what health you’re at, it’s also checking if the player isn’t dead and and the player is below the next highest health value. It also goes up to 200 since I planned health upgrades as a feature. I’m also not the best scripter, so sorry if my code is a bit messy. Thanks for taking some time out of your day to reply and help, I really appreciate it.

@SlinkyShelf0

That was the problem all along apparently, I didn’t even put that into consideration. Thanks for helping out!

1 Like

Glade we could help! :smile:

Have a good day, and happy coding!!

1 Like