function pDM:AddXP(plr,xp)
local exp=DataT[plr.UserId]['XP']
local level=DataT[plr.UserId]['Level']
local prest=DataT[plr.UserId]['Prestige']
exp+=xp
if exp>pDM.LevelSystem['XP_PER_LEVEL']
then
exp=0
level+=1
elseif level>pDM.LevelSystem['LEVELS_PER_PRESTIGE'] then
exp=0
level=0
prest+=1
end
end
pDM.LevelSystem={
['MAX_XP_PER_50'] = 40000;
['XP_PER_LEVEL'] = 800;
['LEVELS_PER_PRESTIGE'] = 50;
}
Error: attempt to compare number < nil
Error Line:
elseif level>pDM.LevelSystem['LEVELS_PER_PRESTIGE'] then
The level variable is nil so that would mean your datastore doesnt not have a level stored for that player so you could assign level to 0 if level does not exist
Level or LEVELS_PER_PRESTIGE is nil, there could be an issue when retrieving the data or its just not set.
You need to make sure that DataT contains the player’s UserId entry at the start of the function and that Level and LEVELS_PER_PRESTIGE are not nil.
function pDM:AddXP(plr, xp)
-- Make sure that DataT contains the player's UserId entry
if not DataT[plr.UserId] then
DataT[plr.UserId] = {
XP = 0,
Level = 0,
Prestige = 0
}
end
local exp = DataT[plr.UserId]['XP']
local level = DataT[plr.UserId]['Level']
local prest = DataT[plr.UserId]['Prestige']
exp = exp + xp
local levelsPerPrestige = pDM.LevelSystem['LEVELS_PER_PRESTIGE']
if levelsPerPrestige and exp > pDM.LevelSystem['XP_PER_LEVEL'] then
exp = 0
level = level + 1
if level > levelsPerPrestige then
exp = 0
level = 0
prest = prest + 1
end
end
DataT[plr.UserId]['XP'] = exp
DataT[plr.UserId]['Level'] = level
DataT[plr.UserId]['Prestige'] = prest
end