Making an NPC spawn with a random model

(Please note, I only know very basic lua)
I have a couple of headhacked models here that use the male citizen heads, and I’m trying to make an NPC that randomly chooses which model to use. I borrowed some code from DatPolishGuy’s Black Mesa NPCs, but nothing happens when I try to spawn them and I get this error in the console.



[ERROR] gamemodes/sandbox/gamemode/commands.lua:349: bad argument #1 to 'SetModel' (string expected, got table)
  1. SetModel - [C]:-1
   2. InternalSpawnNPC - gamemodes/sandbox/gamemode/commands.lua:349
    3. Spawn_NPC - gamemodes/sandbox/gamemode/commands.lua:433
     4. unknown - gamemodes/sandbox/gamemode/commands.lua:463
      5. unknown - lua/includes/modules/concommand.lua:54


Here’s the stuff I used



local CMN_models = {"models/crysis_npcs/crysismale01_npc.mdl"}	
hook.Add("PlayerSpawnedNPC","RandomModel",function(ply,npc)
    if table.HasValue( CMN_models, npc:GetModel() )					
	       then
	npc:SetModel("models/crysis_npcs/crysismale0"..math.random(1,9).."_npc.mdl")	
    end
end)


Any help would be appreciated

That code isn’t causing the problem; a table isn’t being sent in to SetModel

So, what do you suggest I change or add?

Find the actual code that’s erroring. If you can’t, override SetModel and do a type check.