Exp Rollover to next level

How do I make it so that the remaining exp gets rolled over to the next level?
I know It has to do with me putting Exp.Value = 0 but I’m not sure what else to put there to make it rollover and not reset to 0.

local RequiredEXP = Instance.new("IntValue")
RequiredEXP.Name = "RequiredExp"
RequiredEXP.Value = Level.Value * 100
RequiredEXP.Parent = leaderboard

Exp.Changed:Connect(function(Changed)

	if Exp.Value >= RequiredEXP.Value then
		Exp.Value = 0


		Level.Value += 1
		RequiredEXP.Value = Level.Value * 100
end
RolloverExp = Exp.Value - RequiredEXP.Value
-- ...same code as you already had
Exp.Value = RolloverExp

Just keep track of the extra xp gained

1 Like

very basic way of doing it is this

local level = 1
local xp = 1502
local XPNeededToLevel = 100

function xpChanged()
	if xp >= XPNeededToLevel then
		local leftOverXP = xp - XPNeededToLevel
		level += 1
		xp = leftOverXP
		print("Level:",level, "XP:",xp)
		xpChanged() -- in case its over enough xp to level up twice
	end
end


xpChanged()

Image wont upload but it prints this:

Level: 2 XP: 1402 
Level: 3 XP: 1302 
Level: 4 XP: 1202 
Level: 5 XP: 1102 
Level: 6 XP: 1002 
Level: 7 XP: 902 
Level: 8 XP: 802
Level: 9 XP: 702
Level: 10 XP: 602
Level: 11 XP: 502
Level: 12 XP: 402  
Level: 13 XP: 302  
Level: 14 XP: 202
Level: 15 XP: 102 
Level: 16 XP: 2
2 Likes

Now I’m having another problem I don’t know whats causing it but each time I play the game I get a bunch of levels with this in the output. I dont have any parts that gives a lot of Exp for this to be happening

Maximum event re-entrancy depth exceeded for IntValue.Changed