So I'm getting the error below because the events are calling each other continuously sometimes, for instance if a player gets a very large amount of exp. How can I retain functionality and fix this error?
Error: Maximum event re-entrancy depth exceeded for IntValue.Changed
game.Players.PlayerAdded:Connect(function(Player)
local Stats = Player:WaitForChild("Stats")
local Exp = Stats:WaitForChild("Exp")
local Level = Stats:WaitForChild("Level")
local LastLevel = Level.Value
local RequiredExp = math.floor((Level.Value * (Level.Value / 2)) + 10)
Level.Changed:Connect(function()
if Level.Value > LastLevel then
if Exp.Value >= RequiredExp then
Exp.Value = Exp.Value - RequiredExp
end
else
Exp.Value = 0
end
LastLevel = Level.Value
end)
Exp.Changed:Connect(function()
RequiredExp = math.floor((Level.Value * (Level.Value / 2)) + 10)
if Exp.Value >= RequiredExp then
Level.Value = Level.Value + 1
end
end)
end)

1 comment
Both changed events set the Value causing the event to run again and again. Remove the level changed event and only change the level in the Exp changed event.