GeoForts, Secondary swep lua error

So when you try to choose a different secondary swep it won’t render and i get a massive console spam with the following error:


[gamemodes\geoforts\gamemode\cl_init.lua:886] attempt to index local 'ent' (a nil value)

If someone can fix this i would really appreciate it.

And this is the bit of code:

[lua] //Draw weapon
local drawweapon
if ScrW() < 1152 then //Since we can’t draw “off” the screen, we have to compromise
drawweapon = function(ent,x,y,ang,mode) //Width and height is always (256,90) horizontally
cam.IgnoreZ(true)
render.SuppressEngineLighting(true)
local vCamPos = Vector(12,64,0)
local fFOV = 50

			local x = (x or 0) - 128 + 128
			local y = (y or 0) - 210 + 128
			if mode then
				vCamPos.x = -12
				x = x + 140
			end
			
			local ax,ay = self:LocalToScreen(x,y)
			
			local sbox = {0,0,256,90}
			surface.SetDrawColor(0,0,255,10)
			//surface.DrawRect(sbox[1]+x+128,sbox[2]+256+y-46,sbox[3],sbox[4])
			//surface.DrawRect(x,y,256,256)
			
			cam.Start3D(vCamPos,Angle(0,270,0),fFOV,ax,ay,256,256)
				render.SetLightingOrigin(ent:GetPos())
				
				ent:SetAngles(ang or Angle(0,0,0))
				ent:DrawModel()
				
			cam.End3D()
			render.SuppressEngineLighting(false)
			cam.IgnoreZ(false)
		end
	else
		drawweapon = function(ent,x,y,ang) //Width and height is always (256,90) horizontally
			cam.IgnoreZ(true)
			render.SuppressEngineLighting(true)
			local vCamPos = Vector(12,128,0)
			local fFOV = 50
			
			local x = (x or 0) - 128
			local y = (y or 0) - 210
			
			local ax,ay = self:LocalToScreen(x,y)
			
			local sbox = {0,0,256,90}
			//surface.SetDrawColor(0,0,i/#self.Ents*255,255)
			//surface.DrawRect(sbox[1]+x+128,sbox[2]+256+y-46,sbox[3],sbox[4])
			
			cam.Start3D(vCamPos,Angle(0,270,0),fFOV,ax,ay,512,512)
				render.SetLightingOrigin(ent:GetPos())
				
				ent:SetAngles(ang or Angle(0,0,0))
				ent:DrawModel()
				
			cam.End3D()
			render.SuppressEngineLighting(false)
			cam.IgnoreZ(false)
		end
	end

[/lua]