(GAMEMODE) For loop with player models table error...

Hello, Recently I started with making a gamemode for Garry’s Mod. I made a for loop with a table for my player models. I get an error, but I dont know how to fix it. Can someone please help me?

Error: [gamemodes[gamemode_name_unknown]\gamemode\shared.lua:35] attempt to index global ‘ply’ (a nil value)

For loop with table:

PModel = { { “models/player/Group01/Female_01.mdl”,
“models/player/Group01/Female_02.mdl”,
“models/player/Group01/Female_03.mdl”,
“models/player/Group01/Female_04.mdl”,
“models/player/Group01/Female_06.mdl”,
“models/player/Group01/Female_07.mdl”,
“models/player/group01/male_01.mdl”,
“models/player/Group01/Male_02.mdl”,
“models/player/Group01/male_03.mdl”,
“models/player/Group01/Male_04.mdl”,
“models/player/Group01/Male_05.mdl”,
“models/player/Group01/Male_06.mdl”,
“models/player/Group01/Male_07.mdl”,
“models/player/Group01/Male_08.mdl”,
“models/player/Group01/Male_09.mdl” }, { “models/player/police.mdl” },
{ “models/player/combine_soldier_prisonguard.mdl” }, { “models/player/breen.mdl” },
{ “models/player/Group03/Female_01.mdl”,
“models/player/Group03/Female_02.mdl”,
“models/player/Group03/Female_03.mdl”,
“models/player/Group03/Female_04.mdl”,
“models/player/Group03/Female_06.mdl”,
“models/player/Group03/Female_07.mdl”,
“models/player/group03/male_01.mdl”,
“models/player/Group03/Male_02.mdl”,
“models/player/Group03/male_03.mdl”,
“models/player/Group03/Male_04.mdl”,
“models/player/Group03/Male_05.mdl”,
“models/player/Group03/Male_06.mdl”,
“models/player/Group03/Male_07.mdl”,
“models/player/Group03/Male_08.mdl”,
“models/player/Group03/Male_09.mdl” },
{ “models/player/gman_high.mdl” },
{ “models/player/monk.mdl” },
{ “models/player/kleiner.mdl” } }

for k, v in pairs( PModel ) do
if ply:Team() == k then – error line
ply:SetModel (v [math.random (1, table.Count(v) ) ] )
end
end

Need to find player by a parameter of a function or finding them by other source such as name and stuff.

Such as:



	function GM:PlayerSetModel( ply )
		//Your code
	end


Have a look here see what you can find that would suit your need.

Thank you. :smiley:

Next time use [lua.] ^^ [/lua] I like cider, tell me when the server is up