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.

3 comments

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'.

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.

0

Okay, I will try this out. Thanks! I will let you know if it does not work.