So I've been working on a leveling up system for my RPG (which has an XP formula like RuneScape). I've managed to make a carry-over system for it and everything, and it works nicely, to an extent. The problem occurs when I add a lot of XP at a time. In RS, when you add something like 27500 XP, it will put you on level 29, and you'll have some XP leftover, but in my case it doesn't happen.
My Code:
player = game.ServerStorage[Player.Name]
function levelUp()
if player.MeleeEXP.Value >= player.NextMeleeEXP.Value then
player.LeftOverMeleeEXP.Value = player.MeleeEXP.Value - player.NextMeleeEXP.Value
player.MeleeLevel.Value = player.MeleeLevel.Value + 1
player.MeleeEXP.Value = 0 + player.LeftOverMeleeEXP.Value
player.LeftOverMeleeEXP.Value = 0
player.NextMeleeEXP.Value = player.NextMeleeEXP.Value + ( player.MeleeLevel.Value + 300 * (math.pow(2, player.MeleeLevel.Value / 7)) ) / 4
end
end
player.MeleeEXP.Changed:connect(levelUp)

1 comment
A good way to do this is by moving the line(s) of code where you change the amount of experience to an event that listens for the level value being changed.