Walking animations not working for random npcs

So I’m making it so that an npc of the player’s friends walk around in game and I’ve come across a problem with that some npcs aren’t getting their animations; whereas, others do. It’s been really strange because I’m instancing them the exact same way, yet for some reason, a few of the npcs have no animation at all.

If you’re interested, here’s the code that instances the npcs. (There are lot of unrelated values being added for pathfinding

local friendPages = game.Players:GetFriendsAsync(player.userId)
local i = 0`
for item, pageNo in iterPageItems(friendPages) do --loops through friends list
		local playerId = player.userId 
		local playermodel = game.Players:CreateHumanoidModelFromUserId(item.Id) --official instance of npcs
		playermodel.Name = "Player"
		playermodel.Animate:Destroy()
		local locationIden = Instance.new("StringValue") --unrelated value
		locationIden.Name = "npcLocation"
		locationIden.Value = "Part1"
		locationIden.Parent = playermodel
		local npcActive = Instance.new("BoolValue") --unrelated value
		npcActive.Name = "npcActive"
		npcActive.Parent = playermodel
		local NPCAnim = game.Workspace.CopyItems.NpcAnimationScript:Clone() --animation script
		NPCAnim.Name = "Animate"
		NPCAnim.Parent = playermodel
		NPCAnim.Disabled = false
		playermodel.Humanoid.DisplayDistanceType = "None"
		playermodel.Parent = playerTycoon.Pathfinding.Npcs
		for _, playerPart in pairs(playermodel:GetChildren()) do -- sets collision group
			if playerPart:IsA("BasePart") then
				PhysicsService:SetPartCollisionGroup(playerPart, "Npcs")
			end
		end
		playermodel.HumanoidRootPart:SetNetworkOwner(nil)
		playermodel:MoveTo(Vector3.new(-244.058, 96.64, -357.095))
		i = i + 1

	if i > 2 then --sets number of npcs spawn (spawns 3)
		break
	end	
end	

I have no idea why some animations are working and some aren’t. If you have any idea as to why, please let me know.

1 Like

Without seeing any animation code, I can only assume it has something to do with loading order or animations failing to load, although you should see that in the developer console. Maybe you have some error handling in place that is catching errors but not printing them? Maybe the animations are uploaded to a profile in a group game, so the animations would only show up for the uploader? Need more info.

Here’s how the npcs get their animations. I copy the default animation script you have when you join the game, changed it to a server script and made it a child of the npcs. This is what every post has said to do when it comes to giving npcs animations. All of the animations are the default roblox animations.

1 Like

That’s pretty convoluted for animations. I’m not 100% sure about default animations, but custom ones are really easy to play and are much better with replication. Cloning scripts around can cause issues with things not being there when you want them to be, so I would suggest using a bindable event or module of some sort to play animations instead of cloning.

Turns out that it was the players character type that was causing the errors. It’s fixed now.

1 Like