Script keep spawning default rig first time when spawn

Does anyone know my script keep spawning the default rig first then it starting to load the actual appearance id by userid??

rig with no appearance spawning first time even though id is valid:

Then the others rigs spawn with appearance:

Code:

task.spawn(function()
    while task.wait(NPCSpawnSpeed) do
        if PlayersFriendsList[Plr.UserId] ~= 'N/A' then
            print('Spawning...')
            local PlrBuilding = BuildingsFolder:FindFirstChild(Plr.Name)
            
            if PlrBuilding and PlrBuilding:IsA('Model') then
                local NPCsFolder = PlrBuilding:FindFirstChild('NPCs')
                
                if NPCsFolder and NPCsFolder:IsA('Folder') then
                    local NewRig = RigModel:Clone()
                    
                    local NewRigHumanoid = RigModel:FindFirstChildWhichIsA('Humanoid')
                    
                    if NewRigHumanoid then
                        
                        local RandomPlrId = PlayersFriendsList[Plr.UserId][math.random(1, #PlayersFriendsList[Plr.UserId])].VisitorId
                        
                        NewRig.Name = ' '
                        
                        if typeof(RandomPlrId) == 'number' then
                            NewRigHumanoid:ApplyDescription(Players:GetHumanoidDescriptionFromUserId(RandomPlrId))
                        end
                    end
                    
                    NewRig.Parent = NPCsFolder

                    local BuildingDoor = PlrBuilding:FindFirstChild('Door')

                    if BuildingDoor and BuildingDoor:IsA('BasePart') then
                        NewRig:PivotTo(BuildingDoor.CFrame)
                    end
                    
                else
                    warn('Cannot find NPCs folder in player building!!')
                end
            else
                warn('Cannot find player building in buildings folder!!')
            end
        else
            
        end
    end
end)

Try using CreateHumanoidModelFromUserId. It returns the model with the description applied. It will shorten your code and it does automatically what you’re doing manually.

1 Like

It solved the problem but there is no animation for the NPC. What can I do now?

I’m currrently have to clone the animate script to the npc and enabled it.
image

Are those custom animations that you are trying to run?

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.