Changing a player's model

I have this on my init.lua as a command.
function ChangeModel( ply, args )

if( args[1] ) then

	ply:SetModel( args[1] );


concommand.Add( “rp_changemodel”, ChangeModel );

Then a table on the shared.lua with a few model paths.

Then I have this on the cl_init.lua
for k, v in pairs( ModelTable ) do

	local Icon = vgui.Create( "SpawnIcon", IconList );
	Icon:SetModel( v );
	IconList:AddItem( Icon );
	Icon.DoClick = function( Icon, args )

		RunConsoleCommand( "rp_changemodel", v );


I’m basicly adding spawn icons, and when you click them it changes your model, however, when you press it or try it in the console (rp_changemodel modelpath) nothing happens, aka it doesent change your model. Any idea why?

function ChangeModel( Player, Command, Arguments )


You may also need to translate and precache the model.

[lua]local ModelName = player_manager.TranslatePlayerModel( “kleiner” );
util.PrecacheModel( ModelName );
Player:SetModel( ModelName );[/lua]


Also whenever a command doesn’t work try printing out the argument and seeing if it is valid and the code is executing.

in the cl_init.lua I have printed out the loop/table arguements:
print( v )
And it worked, it prints out each model in the console, so I guess it’s the model change command.

I’ve tried pre caching the model (in the model change command) and added ‘cmd’ in the arguements. It seems it has worked. However, the models are T-Posed with no animations.

You sure your using the right models?

models/player/breen.mdl for example.

ModelTable = {




Those are the ones I’m using, should I not be using those type?

Those dont seem to T-Pose but the others do. Are there specific HL2 ‘Player’ Models?

[lua]ModelTable = {



Many thanks, however I get lag when I click the spawn icon when using the util.precache. I could precache them before that, like on the loop right?

I meant print the argument in the init file.

print( args[1] ) for example.

However you fixed that how by fixing your functions parameters. Just thought I’d clear up what I meant.

I pm’d you hours ago. Use ply, cmd, args rather than ply, args.

I already told him that and he already did it and fixed that bit, please read the rest of his thread before replying. :stuck_out_tongue: