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.