Why is my character regenerating the health lost immediately

Hey there!
for some reason, whenever i make the humanoid take damage, it immediately heals it back

script:

while true do
	local tor = script.Parent.UpperTorso:FindFirstChild("Fire")
	
	if tor == nil then
		task.wait(2)
		continue
	else
		local hum = script.Parent.Humanoid
		hum:TakeDamage(6)
		task.wait(1)
	end
end

2 Likes

It’s because there’s a script in the Character that regenerates the health. In fact, it’s called Health and it can only be seen while the game is running on both the server and the client. Here’s a copy of the script:

-- Gradually regenerates the Humanoid's Health over time.

local REGEN_RATE = 1/100 -- Regenerate this fraction of MaxHealth per second.
local REGEN_STEP = 1 -- Wait this long between each regeneration step.

--------------------------------------------------------------------------------

local Character = script.Parent
local Humanoid = Character:WaitForChild'Humanoid'

--------------------------------------------------------------------------------

while true do
	while Humanoid.Health < Humanoid.MaxHealth do
		local dt = wait(REGEN_STEP)
		local dh = dt*REGEN_RATE*Humanoid.MaxHealth
		Humanoid.Health = math.min(Humanoid.Health + dh, Humanoid.MaxHealth)
	end
	Humanoid.HealthChanged:Wait()
end

To stop the regeneration, simply delete the script from the player’s character.

Alrighty, ill try it!

spacefiller

It seems it still doesnt work, no health regen but still not working

I’m testing it myself right now. That should have worked.

When I manually delete that script from the workspace and damage the character, the health does not regenerate. Furthermore, the deletion is replicated to the client. How are you removing the script? Code?

If you’re trying to delete the health gen script, just create a new Script called “Health” in StarterCharacterScripts and remove all of the code inside.

1 Like

Ah right yes, im trying this now

Thank you! it has worked now, this was too big of a thread for a simple solution lol

So basically you’re overriding the original script, similar to how one overrides scripts in the LUA chat system. Interesting.

and similar to how one can override the default ‘Animate’ script too.

2 Likes