I’m struggling to come up with a formula to convert xp into levels.
I want the experience of the next required level to be *1.1 of the previous amount of xp it took to level up.
to go from lvl 1 → 2 would be 100 xp.
lvl 2 → 3 would be 110 xp.
lvl 3 → 4 would be 121 xp.
etc.
I want to store data on the player’s exact xp amount, but I’m not good enough at math to figure out what “level” they are at with math.
The only important parameters here are that lvl 1 starts at 0 xp, and level 2 starts at 100 xp.
I wouldn’t care about math but use a small script
I’d use a table to store all possible levels (maxLevel) with the lower XP limits of the levels (levelLimit).
Then a simple function to search for the actual level from XP (getLevel).
This is a small demo for this, it spams random XPs with the proper level values.
local levelLimit={}
local maxLevel=10
levelLimit[1]=0
levelLimit[2]=100
for i=3,maxLevel do
levelLimit[i]=math.floor(levelLimit[i-1]*1.1)
end
local function getLevel(xp)
local lvl
for lvl=maxLevel,1,-1 do
if levelLimit[lvl]<=xp then
return lvl
end
end
return 0
end
while wait(1) do
local xp=math.random(1,levelLimit[maxLevel])
local lvl=getLevel(xp)
print (xp," xp = level ",lvl)
end
I like math solutions too, thanks for this!
I checked this solution, but it gives me level 1 and 2 for all xp.
116 xp = level 2
175 xp = level 2
25 xp = level 1
22 xp = level 1
47 xp = level 1
132 xp = level 2
At this point we have to use logarithms to move level out of the exponent. logX(Y) is what power do you need to raise X by to reach Y. Therefore logX(X) = 1, logX(X^2) = 2, etc. So logmult(Mult^Level) = Level. Roblox doesn’t actually let us use logarithms of any base, so we have to use a change of base formula:
logX(A) = ln(A) / ln(X)
This doesn’t seem to give the results I’m looking for for some reason.
Level 2 is 100 xp, level 1 is 0 xp, not sure if that’s part of the consideration
For some reason I seem to be about a multitude of 10 off, not sure if it’s an error on my part. Can you substitute your formula with what you think should be in it?
5000 xp seems to give around the amount that would be correct for the amount needed between lvl 43 and lvl 44. But that’s for “amount of xp needed for next level”, not a reflection of “level based off amassed total xp”
Everyone else seems to have made similar mistakes. I’m tweaking with input values and I either get level 7 or level 43 for 5k xp, both of which are way off.
Level 7 should be (I calculated manually) 1143.58881 xp. (1.1k)
I realised the mistake we both made. The total exp required is actually this summation 15759022654533940768931872116852|375x500
I don’t have a good way to simplify that on hand. I’d recommend just making a function that uses an iterative loop like suggested above, or by subtracting the exp needed for the level from the total exp each time they level up and storing the result and the level.
This returns a number, so you probably want to do math.floor to check what level you are certain to pass by getting that much experience. Also it only works for n>=92, for any value below it returns something negative (you could probably just add in a check that if it’s negative, they are level 1).