"Maximum event re-entrancy depth exceeded for IntValue.Changed"

Why is this happening?

local damage = player:WaitForChild("Data").Damage
local Strength =  player:WaitForChild("Data").Strength
Strength.Changed:Connect(function()
	Strength.Value = Strength.Value
end)
damage.Changed:Connect(function()
	damage.Value = damage.Value + Strength.Value
end)

Don’t change the Damage or Strength value inside the actual .Changed event, you’re creating an infinite loop

1 Like

My guess is because of this, you’re firing the Event way too much times every time that gets changed which is resulting in OVER 500,000 CHANGES in a second

Oh, What do i do? Do i put it outside of the .Changed Event?

How do i prevent this form happening again? Do i move the damage.Value part

You could create a dummy IntValue and detect changes in that and send that to the main IntValue

example

DummyIntValue.Changed:Connect(function()
   MainIntValue.Value = DummyIntValue.Value + IntValue.Value
end)

Is there another way other than this?

You could put a debounce inside the .Changed event but depending on the situation, it could mess up your code if the value being calculated is crucial

I did the other one and it works now thanks, but what happens if the same problem happens again?

As far as I know, the problem shouldn’t occur again unless you’re changing the values quickly (for example, every frame) or changing it inside the .Changed event.

1 Like