Why do I get this Error?

I keep getting spammed with this error:

GModRP\gamemode\base/jobs.lua:72: attempt to compare number with nil
GModRP\gamemode\base/jobs.lua:72: attempt to compare number with nil

I don’t see what the problem is can someone fix this for me? or at least tell me what the problem is it would be very much appreciated. :biggrin:


function GMRP.changeJob( p, c, a )

	if !GMRP.UseLimit( p ) then return end
	
	if tonumber( a[1] ) == nil then return end
	
	local jN = tonumber( a[1] )
	local jGN = team.GetName( jN )

	for k, v in pairs( Jobs ) do
	
		if ( jN == Jobs[k][1] ) then
		
			if ( p:Team() == jN ) then
			
				p:RedNotify( "You are already a "..jGN.."." )
				return
				
			end
			
			if ( Jobs[k][2] == "straightupg" ) && ( !p:HasMoney( Configuration["straightupg"] ) ) then
			
				p:RedNotify( "You must have $25,000 to become a Straight Up G" )
				return
				
			end
			
			if ( Jobs[k][3] == "playa" ) && ( !p:HasMoney( Configuration["playa"] ) ) then
			
				p:RedNotify( "You must have at least $20,000 to become a Playa." )
				return

			end
			
			if ( Jobs[k][4] == "gangleader" ) && ( !p:HasMoney( Configuration["gangleader"] ) ) then
			
				p:RedNotify( "You must have at least $15,000 to become a Gang Leader." )
				return

			end
	
			if ( Jobs[k][5] == "gangster" ) && ( !p:HasMoney( Configuration["gangster"] ) ) then
			
				p:RedNotify( "You must have at least $1000 to become a Gangster." )
				return

			end

			if ( Jobs[k][6] == "criminal" ) && ( !p:HasMoney( Configuration["criminal"] ) ) then
			
				p:RedNotify( "You must have at least $5000 to become a Criminal." )
				return

			end

			if ( Jobs[k][7] == "popo" ) && ( !p:HasMoney( Configuration["popo"] ) ) then
			
				p:RedNotify( "You must have at least $10000 to become a PoPo." )
				return

			end

			
			if ( Jobs[k][8] == "citychief" ) && ( !p:HasMoney( Configuration["citychief"] ) ) then
			
				p:RedNotify( "You must have at least $25000 to become a City Chief." )
				return

			end

		
			if ( team.NumPlayers( jN ) < Jobs[k][9] ) then
		
				p:SetTeam( jN )
				p:LoadOut()
				p:GreenNotify( "Job changed to "..jGN.."." )
				
			else
			
				p:RedNotify( "Max "..k.."s reached." )
				
			end	
			
		end

	end
	
end

GMRP.command( "job_change", GMRP.changeJob )

[editline]10:17PM[/editline]

Does anyone know why I’m getting the errors?

If what you posted is the full file then this is the line creating an error :

if ( team.NumPlayers( jN ) < Jobs[k][9] ) then

Could you find that Jobs table and post it here?

I really don’t know what I’m doing. What I was trying to do was Edit gmodrp jobs.lua and make 8 sections for job ranks so you had to have a certain amount of money to play on one of those jobs and I just put the [k] [9] things in order because when they weren’t I kept getting errors so I decided to put them in order and put the last one in k9. Am I missing something?

Here is where the jobs are kept. Shared.lua and I was editing jobs.lua thats where the government system used to be and the government system made it so you had to have at least 1000$ to become a certain job and I’m trying to edit that to make it so my jobs do that too so you have to have 25,000 to become straightupg 20,000 to become a playa 15,000 to become a gangleader 10,000 to become a gangster and 5,000 to become a criminal. I’m just trying to learn how to script by editing small parts of gamemodes and I’m having a hard time.


--[[

	Gangsta RP - Real Gangsta Roleplay.
			By Sgt.Psycho.
		

]]


GM.Name			= "Gangsta RP"
GM.Author		= "Sgt.Psycho"
GM.Email		= "x7076011732x@yahoo.com"
GM.Website		= "http://specialoperations.webatu.com/phpBB3/index.php"

--Sandbox Derived
DeriveGamemode( "sandbox" )


GMRP = {}
GMRP.version = "15beta31"


function GMRP.command( command, func )

	concommand.Add( "gm_rp_"..command, func)
	
end	


include( "configuration.lua" )

CUR = "$"

--citizen models table
citizenmodels = {"models/player/group01/male_02.mdl",
				"models/player/gman_high.mdl",
				 "models/player/odessa.mdl",
				 "models/player/Kleiner.mdl",
				 "models/player/monk.mdl",
				 "models/player/alyx.mdl",
				 "models/player/eli.mdl",
				 "models/player/Group01/male_07.mdl",
				 "models/player/breen.mdl",
				 "models/player/Group01/Female_01.mdl",
				 "models/player/Group01/male_06.mdl",
				 "models/player/mossman.mdl",
				 "models/player/leet.mdl",
			         "models/player/soldier_stripped.mdl",
				 "models/player/phoenix.mdl",
				 "models/player/guerilla.mdl",
				 "models/player/arctic.mdl",
				 "models/player/urban.mdl",
				 "models/player/barney.mdl",
				 "models/player/police.mdl",
				 "models/player/combine_soldier.mdl",
				 "models/player/combine_soldier_prisonguard.mdl",
				 "models/player/combine_super_soldier.mdl",
				 "models/player/Group03/male_06.mdl",
				 "models/player/Group03/male_03.mdl",
				 "models/player/Group03/Female_01.mdl",
				 "models/player/Group03/Male_04.mdl",
				 "models/player/Group03/male_07.mdl",
				 "models/player/Group03/male_09.mdl",
				 "models/player/Group03/Female_07.mdl",
				 "models/player/Group03/male_08.mdl",
				 "models/player/Group03/Male_05.mdl",
				 "models/player/Group03/Male_01.mdl"

				}

Jobs = {}
Jobs["Straight Up G"] = { 1, "Gangs", 5, 82, {}, { "cond_deagle_nocustom", "gmod_rp_lockpick", "keypad_cracker" } }
Jobs["Playa"] = { 2, "Gangs", 10, 69, {}, { "cond_glock_nocustom", "keypad_cracker" } }
Jobs["Gang Leader"] = { 3, "Gangs", 15, 58, {}, { "cond_fiveseven_nocustom" } }
Jobs["Gangster"] = { 4, "Gangs", 20, 46, {}, { "knife", "gmod_rp_lockpick" } }
Jobs["Criminal"] = { 5, "Gangs", 25, 38, {}, { "knife", "keypad_cracker" } }
Jobs["Wangster"] = { 6, "Gangs", 30, 24, {}, { "knife" } }
Jobs["The PoPo"] = { 7, "Pigs", 4, 64, { "PoPo" }, { "stunstick", "gmod_rp_handcuffs", "weaponchecker", "cond_glock_nocustom" } }
Jobs["Doctor"] = { 8, "Neutral", 3, 32, {}, { "med_kit" } }
Jobs["Thief"] = { 9, "Neutral", 3, 22, { "StolenShit" }, { "gmod_rp_lockpick" } }
Jobs["Unemployed"] = { 10, "Neutral", 64, 0, {}, {} }
Jobs["City Chief"] = { 11, "Pigs", 1, 84, { "PoPo" }, { "doorbreech", "cond_deagle_nocustom", "gmod_rp_handcuffs", "cond_m3_nocustom", "Taser" } }
Jobs["Gat Dealer"] = { 12, "Neutral", 3, 32, { "Gatz" }, {} }
Jobs["Whip Dealer"] = { 13, "Neutral", 2, 46, { "Whipz" }, {} }
Jobs["Chef"] = { 14, "Neutral", 3, 36, { "Munchyz" }, {} }
Jobs["Goodyz Dealer"] = { 15, "Neutral", 3, 24, { "Goodyz" }, {} }


for k, v in pairs( Jobs ) do

	team.SetUp( Jobs[k][1], k, Color( 90, 111, 142, 225 ) )

end


local pmeta = FindMetaTable( "Player" )
local emeta = FindMetaTable( "Entity" )

function pmeta:IsOutside()

	local trace = {}
	trace.start = self:GetShootPos()
	trace.endpos = trace.start + ( self:GetUp() * 300 )
	trace.filter = self
	local tr = util.TraceLine( trace )

	if !tr.HitWorld && !tr.HitNonWorld then
	
		return true
		
	end
	
	return false

end				


function pmeta:getJob()

	return team.GetName( self:Team() )
	
end	


function pmeta:isJob( name )

	if ( team.GetName( self:Team() ) == name ) then
	
		return true
		
	end
	
	return false
	
end


function pmeta:RedNotify(str)

	if (SERVER) then
	
		self:SendLua("Notify('"..tostring( str ).."', Color( 255, 0, 0 ) )")
		
	else	
	
		Notify( tostring( str ), Color( 255, 0, 0 ) )
		
	end	
	
end


function pmeta:GreenNotify(str)

	if (SERVER) then
	
		self:SendLua("Notify('"..tostring(str).."', Color(0, 255, 0))")
		
	else	
	
		Notify( tostring(str), Color( 0, 255, 0 ) )
		
	end	
	
end	


function pmeta:BlueNotify(str)

	if (SERVER) then
	
		self:SendLua("Notify('"..tostring(str).."', Color(0, 0, 255))")
		
	else	
	
		Notify( tostring(str), Color( 0, 0, 255 ) )
		
	end	
	
end		


function pmeta:GetPlayerEnergy()

	return tonumber( self:GetNWInt( "energy" ) )
	
end	


include("itembase.lua")
if (SERVER) then

	AddCSLuaFile("itembase.lua")
	
end	


for k, v in pairs( file.FindInLua( "GModRP/gamemode/items/*.lua" ) ) do

	include("items/"..v)
	
	if (SERVER) then
	
		AddCSLuaFile("items/"..v)
		
	end
	
end	


function GMRP.UseLimit( p )

	if CurTime() > p:GetNWInt( "NextUse" ) then 
		
		if (SERVER) then
		
			p:SetNWInt( "NextUse", CurTime() + Configuration["useint"] )
			
		end
		
		return true
		
	else

		p:RedNotify( "Please wait "..math.Round( p:GetNWInt( "NextUse" ) - CurTime() ).." second." )
		
		return false
		
	end

end


function emeta:isOwnable()

	local entClass = self:GetClass()

	if string.find( entClass, "door" ) || string.find( entClass, "vehicle" ) then

		return true
	
	end
	
	return false
	
end


function job( name )

	for k, v in pairs( Jobs ) do
	
		if ( name == k ) then
		
			return Jobs[k][1]
			
		end

	end
	
end


function ef( str )

	if ( tostring( str ) == nil ) then return end

	if string.find( str, "'" ) then
	
		return string.gsub( str, "'", "" )
		
	end
	
	return str

end	

Let me give you a short explanation of what you’re not getting.

In



Jobs = {}
Jobs["Straight Up G"] = { 1, "Gangs", 5, 82, {}, { "cond_deagle_nocustom", "gmod_rp_lockpick", "keypad_cracker" } }

for k,v in pairs( Jobs ) do

k is “Straight Up G”
v is { 1, “Gangs”, 5, 82, {}, { “cond_deagle_nocustom”, “gmod_rp_lockpick”, “keypad_cracker” } }
v[1] is 1
v[2] is “Gangs”

And so on.

Oh and you should give this a good look : http://wiki.garrysmod.com/?title=Lua

So k is for Straight Up G v is for the information after Straight Up G Uhmm thats confusing do you think you could like… I don’t know… Do it for meh :biggrin:

No. :v:

It’s not really hard, try reading on loops and tables.

I’ll probably just study some of this tonight I am trying to become a lua expert. So far I’m doing horrible.

For k,v in pairs (player.GetAll()) do
if (Ply:team() == “Penis”) then
(ply:give(“weapon_penis”)
end

I don’t know the command to find a players team, so don’t nag me for not remembering, i don’t feel like wiki’n it.