Strange Grey Gordon Freeman model - SetModel erro?

Hello guys. I’m trying to set player model in gmod, but is not chaging to my model. It’s changing for a gray Gordon Freeman



function GM:PlayerSetModel(pl)
	modelo = "teste"
	if pl:Team() == TEAM_HUNTERS then
		for i = 1, game.MaxPlayers() do
			if pl == Kills*.Jogador then
				modelo = Kills*.model_player -- Table Kills* will return a string of model path (It's working because Msg("------" .. modelo) is printing: ------------example.mdl)
			end
		end
	end
	pl:SetModel(modelo)
	util.PrecacheModel(modelo)
	Msg("------------" .. modelo)
	
end


When I try to print LocalPlayer:GetModel() I’m recieving: Nil value

Have you overwritten GM:PlayerSpawn() ? If you have you must include self:PlayerSetModel( pl ) within GM:PlayerSpawn( pl )

Yes. I need to call PlayerSetModel now? Because I was changing PlayerModel with an table.random(table_model) and It was working. Without calling in playerSpawn

oh sorry, i didnt read the post properly. I just said that because the wiki says you need to call self:PlayerSetModel if you have a custom GM:PlayerSpawn. If it’s printing ======example.mdl then it must be getting called anyway

you could try posting a PrintTable of Kills so we could see the data that is being used?

I discover the problem. How can I skip a loop when one condition is true?

Fixed, but now I have 2 problems:

First:
I’m trying to force download from a workshop, but when I put
resource.AddWorkshop(CollectionID)

Clients didn’t load the models

Second:
When a Player dies. He drop a ragdoll. How can I avoid that?

for the resource.AddWorkshop( string CollectionID ) problem you could try a few things

  • Make sure the collectionID is a string
  • Make sure the collectionID is correct
  • Unsubscribe from the addon, delete the .gma file from your addons directory, and then join the server to see if you can re-create the problem to make sure the problem definitely exists
  • Post your code

for the ragdolls, you could use http://wiki.garrysmod.com/page/GM/CreateClientsideRagdoll

i don’t exactly know how it works, but since it returns a ragdoll entity, you could (maybe) try this:



--untested
function GM:CreateClientsideRagdoll( ent, ragdoll )
    if ent:IsPlayer() then
        ragdoll:Remove()
    end
end


resource.AddWorkshop( string CollectionID ) is running in init.lua, but outside of any function or event