NPC Schedule bug help

I making SNPC. All fine, but i have one problem. I think that it’s base_ai class problem, but maybe i don’t understand something? When SNPC’s targeted enemy dies or out of sight, SNPC instantly stop playing schedule animation. He use this part of code for melee attack:


if(self.Patriarch_InAttack==0) then
	self:UpdateEnemyMemory(self:GetEnemy(),self:GetEnemy():GetPos())
			
	if(self:GetEnemy():GetPos():Distance(self:GetPos()) < 64) then
		if(!self:IsCurrentSchedule(SCHED_MELEE_ATTACK1)) then
			if(self.NextSoundCanPlayTime<CurTime()) then
				local TEMP_AttackSoundChance = math.random(1,5)
					
				if(TEMP_AttackSoundChance==1) then
					local TEMP_SND = "Tripwire/Killing Floor/Patriarch/VoiceMelee/Melee"..math.random(1,6)..".wav"
								
					self:EmitSound( TEMP_SND, 75, 100, 1, CHAN_VOICE )
					self.NextSoundCanPlayTime = CurTime()+SoundDuration(TEMP_SND)+0.1
				end
			end

			self:StopMoving()
			self:ClearSchedule()
			self:SetSchedule(SCHED_MELEE_ATTACK1)
			self.Patriarch_InAttack = 4

			timer.Create("StartAttack",0.2,1,function()
				if(IsValid(self)&&self!=nil&&self!=NULL) then
					self:StopAllTimers()
					self:MakeMeleeAttack()
				end
			end)
		end
	end
	//Another code...

Function self:StopAllTimers() stop all timers, because i use specific system. I had tried to make npc_ entity, that just move to his enemies and make real enemy be a variable, but it create more problems and not fix problem with enemy out of sight. Any ways to fix animation stopping?