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

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

Asked by 7 years ago

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)

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. M39a9am3R 3210 — 7y

1 answer

Log in to vote
1
Answered by
RubenKan 3615 Moderation Voter Administrator Community Moderator
7 years ago
Edited 7 years ago

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)

Ad

Answer this question