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

Receiving "Maximum event re-entrancy depth exceeded for IntValue.Changed" Error on big numbers?

I'm working on a level system, and it seems to be working pretty smoothly,

Although the coding is probably more inefficient than Roblox 1.0 ;)

However whenever large amounts of Exp are sent to the XP stat I get this error. Console Screenshot

The Script in the workspace that's erring

game.Players.PlayerAdded:connect(function(player)
	local stats = Instance.new('Folder', player)
	stats.Name = 'leaderstats'
	local experience = Instance.new('IntValue', stats)
	experience.Name = 'EXP'
	experience.Value = 0
	local level = Instance.new('IntValue', stats)
	level.Name = 'Level'
	level.Value = 0
	
	experience.Changed:connect(function()
		if math.floor((level.Value + 1)* 1000) <= math.floor(experience.Value) then
			level.Value = level.Value + 1
			experience.Value = math.floor(experience.Value) - math.floor((level.Value * 1000))
			wait()
			if math.floor((level.Value + 1)* 1000) <= math.floor(experience.Value) then
				level.Value = level.Value + 1
				experience.Value = math.floor(experience.Value) - math.floor((level.Value * 1000))
				wait()
			else
				return
			end
		elseif math.floor((level.Value + 1)* 1000) >= math.floor(experience.Value) then
			return
		end
	end)
end)

Script in startergui handling animation/display

local leaderstats = game.Players.LocalPlayer:WaitForChild('leaderstats')
local xp = leaderstats:WaitForChild('EXP')
local level = leaderstats:WaitForChild('Level')
local nlevel = nil
local CurrLev = script.Parent.Parent.Parent.Frame_EXPBar:WaitForChild("Label_CurrentLevel")
local NextLev = script.Parent.Parent.Parent.Frame_EXPBar:WaitForChild("Label_NextLevel")
local xpBar = script.Parent.Parent.Parent.Frame_EXPBar
local xpBarFill = script.Parent.Parent.Parent.Frame_EXPBar.Frame_EXPBarFill

function update()
	local Math = (((level.Value + 1)*1000) - xp.value)/((level.Value + 1)*1000)
	xpBarFill:TweenSize(UDim2.new(1-Math,0,1,0),"Out","Quart",.5,true)
	if  Math >= ((level.Value+1)*1000) then
		xpBarFill:TweenSize(UDim2.new(0,0,1,0),"Out","Quart",.5,true)
	else
		xpBarFill:TweenSize(UDim2.new(1-Math,0,1,0),"Out","Quart",.5,true)
	end
	CurrLev.Text = level.Value
	NextLev.Text = level.Value + 1
	
end

xp.Changed:connect(function()
	update()
end)
level.Changed:connect(function()
	update()
end)

1 comment

0

Line 14 and line 18, it looks like you're modifying experience in an event that detects experience changes. This may be an area of issue another user may help solve.

1 answer

✓ Accepted answer

This happens when you use a Instace.Changed event, and change the Instance the Changed event fires on, inside the same function. Since you're using quite a lot of changed events, i'm not going to post any fixed code.

This would cause the error:

local v = Instance.new("IntValue")

v.Changed:Connect(function()
	v.Value = v.Value + 1
end)

v.Value = v.Value + 1

as it updates the value inside the Changed event, wich triggers the Changed event again, and again, and again. (This is called recursion)

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