Nil Value

This error


[ERROR] gamemodes/metrorp/gamemode/init.lua:800: attempt to index field '_ModelChoices' (a nil value)
  1. PlayerSetModel - gamemodes/metrorp/gamemode/init.lua:800
   2. unknown - gamemodes/metrorp/gamemode/init.lua:837
    3. Spawn - [C]:-1
     4. WakeUp - gamemodes/metrorp/gamemode/metatables/sv_player.lua:390
      5. unknown - gamemodes/metrorp/gamemode/init.lua:834
       6. Spawn - [C]:-1
        7. Call - gamemodes/metrorp/gamemode/init.lua:657
         8. LoadData - gamemodes/metrorp/gamemode/metatables/sv_player.lua:666
          9. unknown - gamemodes/metrorp/gamemode/init.lua:681

come up when I start my server. HOWEVER it all is because of this part of the stack overflow


[ERROR] gamemodes/metrorp/gamemode/init.lua:800: attempt to index field '_ModelChoices' (a nil value)

This is the line it is getting the error at:


local model = models[ply._ModelChoices[string.lower(ply._Gender)][ply:Team()] ]

Am I missing something here? Looks fine to me.

_ModelChoices doesn’t exist inside the player table.

I found this.


function GM:PlayerInitialSpawn(ply)
	if ( IsValid(ply) ) then
		ply:LoadData();
		
		ply._ModelChoices = {}
		for _,team in pairs(cider.team.stored) do
			for gender,models in pairs(team.models) do
				ply._ModelChoices[gender] = ply._ModelChoices[gender] or {}
				if #models ~= 1 then
					ply._ModelChoices[gender][team.index]
						= math.random(1,#models)
				else
					ply._ModelChoices[gender][team.index] = 1
				end
			end
		end

So it is getting declared so I have no idea.

Try running this in RCON ( Assuming you’re the only player connected )

lua_run print( PrintTable( player.GetAll()[ 1 ]._ModelChoices ) )

edit:

Maybe for some reason the Player wasn’t valid ( Wild guess ) and the statement returned false, so run this as well:

lua_run GAMEMODE:PlayerInitialSpawn( player.GetAll()[ 1 ] )

1st:


> print( PrintTable( player.GetAll()[ 1 ]._ModelChoices ) )...
male:
1 = 1
2 = 1
3 = 1
4 = 2
5 = 2
6 = 1
7 = 1
8 = 1
9 = 1
10 = 9
11 = 1
12 = 1
13 = 1
14 = 1
15 = 1
16 = 1
female:
1 = 1
2 = 1
3 = 1
4 = 2
5 = 1
6 = 1
7 = 1
8 = 1
9 = 1
10 = 5
11 = 1
12 = 1
13 = 1
14 = 1
15 = 1
16 = 6

2nd:


> GAMEMODE:PlayerInitialSpawn( player.GetAll()[ 1 ] ) ...
LOADING DATA
ServerLog: [Debug] [M] FallenMoons is new to the server. Data not loaded.
[Debug] [M] FallenMoons is new to the server. Data not loaded.
ServerLog: [Teams] [M] FallenMoons changed team from "Citizen" to "Citizen".
[Teams] [M] FallenMoons changed team from "Citizen" to "Citizen".
ServerLog: [Event] [M] FallenMoons finished connecting.
[Event] [M] FallenMoons finished connecting.
DATA LOADED

[editline]2nd January 2014[/editline]

Ran both. So the table does have info and is being defined.

_ModelChoices does not exist at the point in time when the code is ran.