Error on old gmod 12 gamemode

So me and a couple of friends decided to download and update an old gamemode created for gmod 12 so we could play it on a private server and upload it to workshop for others to download (since their isn’t an updated version of the gamemode on workshop). We were able to update its files so we could select it from the menu but our knowledge on coding ends there. We ran into an error with the gamemode that is displayed below:


[ERROR] gamemodes/gofish/gamemode/cl_init.lua:160: attempt to index field 'rod' (a nil value)
  1. unknown - gamemodes/gofish/gamemode/cl_init.lua:160

With line 160 being:


	local w = 8 + self.rod:GetIconSize() + 8 + self.hook:GetIconSize() + 8 + self.bait:GetIconSize() +  8

which is nested in:


function PANEL:Paint() 
	local w = 8 + self.rod:GetIconSize() + 8 + self.hook:GetIconSize() + 8 + self.bait:GetIconSize() +  8
	local h = 8 + self.rod:GetIconSize() + 8 + self.volume:GetTall() + 8
	draw.RoundedBox( 8, 0, 0, w, h, Color(150, 150, 150, 255) )
	draw.RoundedBox( 8, 0+3, 0+3, w-6, h-6, Color(50, 50, 50, 255) )
end 

Does anybody know how to fix this problem?

Find where self.rod is defined and see why its returning nil, if you can’t figure it out post the code where the rod variable is defined. It’s also possible the next few custom variables might return nil after you fix the rod variable.

Might be better to post the whole gamemode on a github or something of the sort if the creator of the gamemode allows it. Makes it easier to help fix it for other people.

I downloaded the gamemode from here: https://garrysmods.org/download/8163/go-fish-2

and the parts I found with self.rod are shown below:


self.rod = vgui.Create( "SpawnIconFish", self ) 
 	self.rod:SetModel( "models/props_junk/harpoon002a.mdl", 0 )
 	self.rod:SetIconSize( 64 ) 
	self.rod.DoClick = function() ply:ConCommand("say !rod") end
	--self.rod:SetToolTip( Format( "%s", "Create a fishing rod" ) ) 


function PANEL:Paint() 
	local w = 8 + self.rod:GetIconSize() + 8 + self.hook:GetIconSize() + 8 + self.bait:GetIconSize() +  8
	local h = 8 + self.rod:GetIconSize() + 8 + self.volume:GetTall() + 8
	draw.RoundedBox( 8, 0, 0, w, h, Color(150, 150, 150, 255) )
	draw.RoundedBox( 8, 0+3, 0+3, w-6, h-6, Color(50, 50, 50, 255) )
end 

function PANEL:PerformLayout()
	local w = 8 + self.rod:GetIconSize() + 8 + self.hook:GetIconSize() + 8 + self.bait:GetIconSize() +  8
	local h = 8 + self.rod:GetIconSize() + 8 + self.volume:GetTall() + 8

“self.Rod” is likely not being created. I see you have this line;


 self.rod = vgui.Create( "SpawnIconFish", self )  

“SpawnIconFish” is of course not a default element, perhaps see if that element is being correctly defined?