Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by
Lagfss 36
1 year ago
Edited 1 year ago
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

Log in to vote
0
Answered by
3F1VE 257 Moderation Voter
1 year ago

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

Ad
Log in to vote
0
Answered by
iiii676 23
1 year ago

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.

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 Lagfss 36 — 1y

Answer this question