Making Citizens Have Random Bodygroups

My friend and i just made a citizen pack but they have too many bodygroups and it is hard to change them every time i spawn the npcs. Does anyone know how do i make them spawn with random bodygroups and skins automatically?

On the initialize function, you must change the bodygroups trhought all them
That’s how usually works

Can you explain it some more because im pretty new to that kind of stuff


After spawning the npc, you’d do this:

for k, v in pairs( it:GetBodyGroups( ) ) do
  it:SetBodygroup(, math.random( 0, v.num - 1 ) )

You’ll have to hook PlayerSpawnedNPC so “it” would the npc that you spawned.

it didnt seem to work, here is what i have

local GPD = { “models/GPD/male_01_default.mdl”,
npc:SetSkin( math.random(0,1) )
npc:SetBodygroup( 2, math.random(0,1) );
npc:SetBodygroup( 3, math.random(0,1) );
npc:SetBodygroup( 4, math.random(0,1) );
npc:SetBodygroup( 5, math.random(0,1) );




local function GPDNPCSpawned( pl, npc )
  if npc:GetModel( ):lower( ):match( "^models/gpd/" ) then
    npc:SetSkin( math.random( 0, 1 ) )
    for i = 2, 5 do
      npc:SetBodygroup( i, math.random( 0, 1 ) )

hook.Add( "PlayerSpawnedNPC", "GPD NPC Spawn", GPDNPCSpawned )

Something more like that is what you can do.

Thanks guys for helping me out, i wouldn’t have done it without you guys.