Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Maximum event re-entry depth exceeded for NumberValue.chaned?

exp.Changed:Connect(function()
	if exp.Value >= required_exp.Value then
		exp.Value -= required_exp.Value
		level.Value += 1
		required_exp.Value = level.Value * 100
		Player.Character.Humanoid.MaxHealth += 4
	end
end)

For no reason at all this code does not work with large numbers, it has worked perfectly fine with no issues from other methods of getting XP within the game. But when I decided to add a code system that grants 1k XP using a code it suddenly breaks. I've read about this issue in which its due to the value infinitely changing within the function but I absolutely fail to see how it would infinitely loop due to me changing the value up until the exp value is less than the required xp value. it somehow creates xp out of nowhere with my system you should end up at lvl 5 but instead im somehow at lvl 9 even though lvl 5-6 have more xp requirements combined than what is given.

2 answers

✓ Accepted answer

Use exp:GetPropertyChangedSignal("Value"):Connect(function() because it saves on resources

In the script you change the xp value, which triggers the script to fire again which changes the xp again, which causes it to trigger over and over again and exceed the limit.

1 comment

0

I understand this, the point I dont get is within the if statement it will not run if the value is not greater than or equal to the required exp so it wouldnt change again

This discussion is preserved as it was. New answers, comments, and votes are closed.