attempt to concatenate local 'levelMultiplier' (a nil value)
7 replies, posted
Hello i have a problem.
I would like to do COD4 like XP levelling (for example: If the player is level 1, then he need to have 30 xp to level up).
The error is here: attempt to concatenate local 'levelMultiplier' (a nil value)
And the line is here:
function ply:GetReqXP()
local requiredXP = nil
if playerLevel == 1 then
local requiredXP = ( 30 )
end
self:SetNWInt( "Level_xp_max", requiredXP )
print( self:Nick() .. " needs " .. requiredXP .. " xp to level.")
end
You are localising twice which isn't working.
function ply:AddXP( amount )
local playerLevel = self:GetNWInt( "Level", 1 )
local savedXP = self:GetNWInt( "Level_xp", 0 )
local maxXP = self:GetNWInt( "Level_xp_max", 100 )
The playerlevel defined here
They are local to ply:AddXP function
So, how to delocalised the playerlevel
function ply:GetReqXP()
local playerLevel = self:GetNWInt( "Level", 1 ) -- like this ;)
local requiredXP = nil
if playerLevel == 1 then
local requiredXP = 30
end
self:SetNWInt( "Level_xp_max", requiredXP )
print( self:Nick() .. " needs " .. requiredXP .. " xp to level.")
end
You can switch to NW2 functions, btw. Just rename all of your [Set/Get]NWInt to [Set/Get]NW2Int (works on all of them, not just Int)
There's actually two issues here.
You'll always get that error so long as the player is anything but Level 1, as you've written it.
You're localizing "requiredXP" twice, so if the player does happen to be Level 1, requiredXP will only equal 30 under the if statement, so it wont make it to your network variable and print calls.
This should be the correct version:
local requiredXP -- Same as saying local requiredXP = nil
if playerLevel == 1 then
requiredXP = 30 -- Don't localize it twice, so remove local beside it
end
if requiredXP then -- Only called if requiredXP isn't nil, to avoid your error
self:SetNWInt("Level_xp_max", requiredXP)
print(self:Nick() .. " needs " .. requiredXP .. " xp to level.")
end
Depending on how you're actually doing your level system.
the same error
Sorry, you need to Log In to post a reply to this thread.