I tweaked your tutoal a little bit and made a different version. Just smooten some rough edges. This is what i did when you get experience. My variables are:
XP - current XP in level.
XP overflow - the leftovers when you level up so you can add them to next level
Max level - max level
XP required for next level - requirement
EXP IN - experience you gain when killing monster.
Now in the give experience i do this.
I subtract the current XP and required XP so in example if you have 900 xp and you need 1000 xp, when you kill monster you get example 500 xp then the leftovers are 1400 - 1000 = 400 xp. So leftover is 400.
If you happen to level up this happens in level up function:
The requirement for the next level increases by 1000 * player level by every level then we reset everything and add the leftovers to the XP. We dont actually need the calculate level progress at all. If you see some errors let me know