"Maximum event re-entrancy depth exceeded for Humanoid.HealthChanged"

Greetings, I am attempting to make a script when activated makes a target take 25% more damage, however it displays Maximum event re-entrancy depth exceeded for Humanoid.HealthChanged in the console when i attempt to do so. I believe I’m missing something to do with optimization, but I’m not sure how to fix it.

Script segment:

	if ExtraDamage == true then
		local TargetPrevHealth = Target.Humanoid.Health
		
		Target.Humanoid.HealthChanged:Connect(function()
			local TargetCurrHealth = Target.Humanoid.Health
			Target.Humanoid.Health = TargetCurrHealth - (Target.Humanoid.Health / 25)

			local TargetPrevHealth = Target.Humanoid.Health

You are making an infinite loop. There is no time for the script to yield.
You have a connection to when the health is changed, but you change the health in the connection which will just cause the function connected to the connection to just be called again.

Example:

abc.Event:Connect(function()
    abc:Fire()
end

when abc is fired it will call the function connected to it which also fires abc so it will make an infinite loop

1 Like

Ah… Yeah, I definitely see that now! I’ll try to fix it. Thanks.