Errors with animation script

Hello, I am trying to fix these very annoying bugs with my script


Here is the location of the anim
image

Part of the script that errors:

function AI.new(NPC,WalkAnim,AttackType,idleAnim)
	CollectionService:AddTag(NPC,NPC.Name)
	CollectionService:GetInstanceAddedSignal(NPC.Name):Connect(function(NPC)
		local Team = NPC.Parent.Name
		local NPCProperties = setmetatable({},AI)
		local hum = NPC.Humanoid
		local humrp = NPC.HumanoidRootPart
		local WalkAnim = hum:LoadAnimation(WalkAnim)
		local RunOnce = false
		local MeleeDB = false
		local NPCHitbox = nil

		if idleAnim then
			idleAnim = hum:LoadAnimation(idleAnim)
			NPCProperties.IdleAnim = idleAnim
			idleAnim:Play()
		end

		NPC.PrimaryPart:SetNetworkOwner(nil)

I’ve tried many things to fix it, like a :WaitForChild(‘Humanoid’) and doing a pcall aswell as a repeating for loop as a way to brute force it to work.

ps: I have multiple AI units using this script, and that is why there is an if statement for detecting if the idleanim is a thing, as some ai don’t have one.

anyone? I really need help with this and I need it quite badly.

you could just add the default roblox Animate script to the NPCs you have and change the ids to your own

I don’t think that is going to work, I would much rather prefer a way to include the animations inside of my actual script

if it helps, I included a print statement in the if idleanim then statement and here are the results
image

u need un Anchor the HumanoidRootPart of the npc
cuz you trying to call BasePart:SetNetworkOwner on anAnhcored Part

I’m sorry but the humanoidrootpart is unanchored, along with everything else.

1 Like