Using for loops with tables


preloadWeps={} 
preloadWeps[1]="models/weapons/w_dber_m4me.mdl"


for k, v in pairs( preloadWeps ) do
	
	util.PrecacheModel( v )

end

I’m trying to precache all these high-res sweps i have on my server as they take 4-5 seconds to load in once you spawn them. Since there are quite a few of them, im attempting to use a table to do it for me.
The code above returns an error as shown here


[ERROR] gamemodes/x/gamemode/shared.lua:17: bad argument #1 to 'pairs' (table expected, got nil)
  1. pairs - [C]:-1
   2. unknown - gamemodes/x/gamemode/shared.lua:17
    3. include - [C]:-1
     4. unknown - gamemodes/x/gamemode/cl_init.lua:1

I’ve looked up on the wiki how to print a table, but for some reason it doesn’t work for me.

Define that table as a local value for the file (put local behind preloadWeps={})

This would work as well as the thing said in the post above:



local preloadWeps = {

	"models/weapons/w_dber_m4me.mdl", -- this will be the first key since it automatically sets it to be if you don't have a defined key for it

	--Just put the model path and a comma after it for every weapon/model

} 


for k, v in pairs( preloadWeps ) do
	
	util.PrecacheModel( v )

end


Thank you, it runs now without error, but it still lags when I load in the weapon. Should I do the same for the view model?