Attempt to compare nil to number

Hey,

So I found this old gamemode from back into 2013 and tried to start it up, all worked out well except for this part which causes drastic problems.

[ERROR] gamemodes/perp/gamemode/_shared/player.lua:386: attempt to compare nil with number

  1. GetXPLevel - gamemodes/perp/gamemode/_shared/player.lua:386
  2. DrawHAS - gamemodes/perp/gamemode/_client/gui/hud.lua:1257
    3. unknown - gamemodes/perp/gamemode/_client/gui/hud.lua:3077


function PLAYER:GiveXP(amt)
	if CLIENT then return end
	local total = amt + tonumber(self:GetNWString("xp"))
	if tonumber(self:GetNWString("xp")) >= 100000 || total >= 100000 then 
		self:SetNWString("xp", 100000)
	else
		self:SetNWString("xp", tostring(tonumber(self:GetNWString("xp")) + amt))
	end
	 
	GDB:Query("UPDATE `_rp_users` SET `xp`='" .. self:GetNWString("xp") .. "' WHERE `uniqueid`='" .. self:UniqueID() .. "'");
end

function PLAYER:TakeXP(amt)
	if CLIENT then return end
	self:SetNWString("xp", tostring(tonumber(self:GetNWString("xp")) - amt))
	GDB:Query("UPDATE `_rp_users` SET `xp`='" .. self:GetNWString("xp") .. "' WHERE `uniqueid`='" .. self:UniqueID() .. "'");
end

function PLAYER:GetXP()
	if self:GetNWString("xp") then
		return self:GetNWString("xp")
	else
		return 0
	end
end

function PLAYER:GetXPLevel()
	if !self.Loaded && SERVER then return end
	if self:GetNWString("xp") then
386.		if tonumber(self:GetNWString("xp")) < 1000 then
			return 0
		else
			return tonumber(string.Left(self:GetNWString("xp"), tonumber(string.len(tostring(self:GetNWString("xp")))) - 3))
		end
	else
		return 0
	end



Help me pleas, how can i get this working?

Change all instances of self:GetNWString(“xp”) to self:GetNWString(“xp”, 0). Note that this is a quick fix and only masks the true issue of the NWString not being set.

Thanks, it worked.