Attempt to index a nil value.

Hello, I added some custom weapons to the gamemode f2s:stronghold and now when I navigate through the weapon buy/select menu I get the following error:

[ERROR] gamemodes/stronghold/gamemode/vgui/sh_loadoutpanel.lua:430: attempt to index a nil value

  1. unknown - gamemodes/stronghold/gamemode/vgui/sh_loadoutpanel.lua:430

On this line:



local timeleft = (time == -1 and -1 or time-ostime)


Well, it looks like time or ostime is nil. Can you post more of the code?



function PANEL:DoRefreshLicenses()
	local ply = LocalPlayer()
	local ostime = os.time()
	
	-- Make sure these are checked for gamemode reloads
	local primary = ply:GetLoadoutPrimary()
	local secondary = ply:GetLoadoutSecondary()
	local explosive = ply:GetLoadoutExplosive()

	self.PrimaryList:Clear()
	for class, time in pairs(ply:GetLicenses(1)) do
		local timeleft = (time == -1 and -1 or time-ostime)
		local tbl = GAMEMODE.PrimaryWeapons[class]
		if tbl and (timeleft == -1 or timeleft > 0) then
			local line = self.PrimaryList:AddLine( tbl.name, (timeleft != -1 and UTIL_FormatTime(timeleft,true) or "~") )
			line.weaponclass = class
			if class == primary then
				line:SetSelected( true )
				self.PrimaryList:OnRowSelected( _, line )
			end
		end
	end
	self.PrimaryList:SortByColumn( 1, false )


[editline]28th August 2015[/editline]

I have tried more than one pack of sweps and I get the same error

Put a print in your for loop and see what time is.



print(time)