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

Leveling System script won't give value to "Current"?

Asked by
QNCL0 5
3 years ago
Edited by Ziffixture 3 years ago

Please encode Lua code in the Lua block code tag (look for the Lua icon in the editor).

Hello, I am a new programmer and sadly, I don't know much about scripting. I have been trying the script listed below to safe data for a XP-Clicker type game. I got this error message. " Maximum event re-entrancy depth exceeded for IntValue.Changed."

And here is the script with the trouble.

--[Author: QNCL0]--

game.Players.PlayerAdded:Connect(function(player)
    local level = Instance.new("IntValue", player)
    level.Name = "Level"
    level.Value = 1

    local XP = Instance.new("IntValue", level)
    XP.Name = "Current"
    XP.Value = 0

    local maxXP = Instance.new("IntValue", level)
    maxXP.Name = "Max"
    maxXP.Value = 100


    XP.Changed:Connect(function(val)
        if XP.Value >= maxXP.Value then


            player.Level.Current.Value = player.Level.Current.Value + 1
            XP.Value = 0
            maxXP.Value = maxXP.Value * 1.33 -- Changes how much it multiplies when leveled up
        end
    end)
end)

workspace:WaitForChild("GiveXP").ClickDetector.MouseClick:Connect(function(player)
    player.Level.Current.Value = player.Level.Current.Value + 33 --Gives the player XP
end)

In this script, I am trying to add a value to "Current" everytime it hits the maximum amount.

0
Line 19 is triggering the '.Changed' Event to fire, which will execute the designated callback once again, ultimately ending up in an exhaustive recurse. As you named it, 'Current' refers to the XP IntValue, I assume you meant 'level.Value += 1'. Ziffixture 6913 — 3y
0
^^^ Also one more thing you want to wrap the maxXP.Value * 1.33 inside a math.floor(), since maxXP is an intValue and can't store decimals. thecelestialcube 123 — 3y
0
Okay, I will try this out. Thanks! I will let you know if it does not work. QNCL0 5 — 3y

Answer this question