Continue Pathfind Logic after npc's death

  1. What do you want to achieve? Keep it simple and clear!
    Stated before im trying to pathfind for every existing NPC even After death!
  2. What is the issue? Include screenshots / videos if possible!
    My issue stands where whenever the AI dies it’s not able to continue pathfinding for that respawned NPC
------------------------- Repawning NPC's -------------------------
local PathFinding = require(game.ReplicatedStorage.Modules.Pathfinding)
local NpcMod = require(game.ReplicatedStorage.Modules.NpcClass)

local AIClass = NpcMod.new()


local lastUpdateTime = tick()

for _, Folder in ipairs(game.Workspace.Alive.QuestNpcs:GetChildren()) do
	if Folder:IsA("Folder") then
		for i,Npc in ipairs(Folder:GetDescendants()) do
			if Npc:IsA("Model") and Npc:FindFirstChild("Humanoid") then
				local Humanoid = Npc:FindFirstChild("Humanoid")

				Humanoid.Died:Connect(function()
					Npc:SetAttribute("IsDead", true)
					AIClass:Respawn(Npc)
				end)
			end
		end	
	end
end

Rs.Heartbeat:Connect(function()
	debug.profilebegin("Heartbeat Npc")
	for _, Folder in ipairs(game.Workspace.Alive.QuestNpcs:GetChildren()) do
		if Folder:IsA("Folder") then
			for i,Npc in ipairs(Folder:GetDescendants()) do
				if Npc:IsA("Model") and Npc:FindFirstChild("Humanoid") then
					local Humanoid = Npc:FindFirstChild("Humanoid")

					if not Npc:GetAttribute("IsDead") then -- Continue PathFinding
						local PathfindType = Npc:GetAttribute("PathfindType")

						if PathfindType == "Basic" then
							AIClass:BasicPathfind(Npc)
						elseif PathfindType == "Advanced" then
							AIClass:SmartPathfind(Npc)
						end
		
						
					end
				end
			end	
		end
	end
	lastUpdateTime = tick()
	
end)

image

  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    Not able to find any forum Post relative to my issue, I have tried using a childadded event that didn’t work out
1 Like