Animations not loading properly when cloned

Hello,

I was testing new enemies for my game and noticed an issue when they spawn in. Enemies spawning for will have a chance have their animations not load properly. This usually leads to enemy having their animations not complete the full motion. I also have this issue for other enemies (not shown in the video) but it is less common. Is this a programming issue or a Roblox limitation?

How it’s supposed to look: https://youtu.be/ZozNo543mlY

How bugged animations look: https://youtu.be/CHzFlfN0FJY

Spawning Function, which is inside a module script and is being called by a server script. The enemy cloner is stored in server storage.

Objects inside the enemy, the meshparts contain motor6ds and i used this enemy to make animations.
image

local function spawnEnemy(character)
	coroutine.wrap(function()
		local raycastorigin = character.HumanoidRootPart.Position + Vector3.new(math.random(-30,30),150,math.random(-30,30))
		local raycastDirection = Vector3.new(0,-500,0)
		local raycastresult = workspace:Raycast(raycastorigin,raycastDirection)
		if raycastresult then
			VFX(1,raycastresult.Position+Vector3.new(0,3.25,0))
			local Enemy = math.random(1,5)
			if Enemy == 1 or Enemy == 2 or Enemy == 3 then
				Enemy = enemyFolder:FindFirstChild("Drako"):Clone()
				spawnWaveCD += 10
			elseif Enemy == 4 or Enemy == 5 then
				Enemy = enemyFolder:FindFirstChild("Scout"):Clone()
				spawnWaveCD += 14
			elseif Enemy == 6 then
				Enemy = enemyFolder:FindFirstChild("Goblin Mage"):Clone()
				spawnWaveCD += 20
			end
			Enemy.Parent = NPCFolder
			
			task.wait(1.5)

			Enemy:SetPrimaryPartCFrame(CFrame.new(raycastresult.Position+Vector3.new(0,3.25,0)))
			local status = Enemy:WaitForChild("Status",1)
			Enemy.Status.Value = "TRACKING"

			raycastresult = nil
		end
	end)()
end

mmmm this might be a task for… #help-and-feedback:scripting-support !

This issue has been solved. This was caused by my enemy targeting system immediately targeting players and not giving the script time to load the animations onto the animator properly. I solved it by placing the enemy into the workspace but not running any AI scripts until the animations were fully loaded.