NPC stops fallowing players after target dies?

After the player dies npc stops following any player any help?

local DISTANCE = 70

local Players = game:GetService("Players")
local PathfindingService = game:GetService("PathfindingService")
local origin = script.Parent.Head 
local equip = script.Parent:WaitForChild("Humanoid").Animator:LoadAnimation(script.Parent.Anims.Equip)
local idle = script.Parent:WaitForChild("Humanoid").Animator:LoadAnimation(script.Parent.Anims.Idle)
local fire = script.Parent:WaitForChild("Humanoid").Animator:LoadAnimation(script.Parent.Anims.Fire)
local walk = script.Parent:WaitForChild("Humanoid").Animator:LoadAnimation(script.Parent.Anims.Walk)
walk:Play()
db = false
coroutine.wrap(function()
	while task.wait() do
		for _, player in pairs(Players:GetPlayers()) do 
			if player.Character  then 
				local HumanoidRootPart = player.Character:FindFirstChild("HumanoidRootPart")
				local rayParams = RaycastParams.new()
				rayParams.FilterDescendantsInstances = {player.Character, workspace.Map}
				rayParams.FilterType = Enum.RaycastFilterType.Whitelist
				local result = workspace:Raycast(origin.Position, CFrame.lookAt(origin.Position, HumanoidRootPart.Position).LookVector * DISTANCE, rayParams) 
				if result and result.Instance:IsDescendantOf(player.Character) then
					local name = player.Name
					script.Parent.Head.face.Transparency = 0
					idle:Play()
					equip:Play()
					local numberrandom = math.random(1,5)
					if db == false then
						db = true
						fire:Play()
						game.Workspace:WaitForChild(name):WaitForChild("Humanoid").Health -= 25
						script.Shoot:Play()
						wait(2)
						db = false
					end
					script.Parent.Head.face.Transparency = 1
				end
			end
		end
	end 
end)();
local RunService = game:GetService("RunService")
db = false
while wait() do
	for _, player in pairs(Players:GetPlayers()) do 
		if player.Character  then 
			local HumanoidRootPart = player.Character:FindFirstChild("HumanoidRootPart")
			local rayParams = RaycastParams.new()
			rayParams.FilterDescendantsInstances = {player.Character, workspace.Map}
			rayParams.FilterType = Enum.RaycastFilterType.Whitelist
			local result = workspace:Raycast(origin.Position, CFrame.lookAt(origin.Position, HumanoidRootPart.Position).LookVector * DISTANCE, rayParams) 
			if result and result.Instance:IsDescendantOf(player.Character) then
				local char = game.Workspace:FindFirstChild(player.Name)
				if char then
					wait()
					local name = player.Name
					local ObjectPosition = game.Workspace:WaitForChild(name).PrimaryPart.Position
					script.Parent.PrimaryPart.CFrame = CFrame.new(script.Parent.PrimaryPart.Position, Vector3.new(ObjectPosition.x, script.Parent.PrimaryPart.Position.y, ObjectPosition.z))
					local function FollowPlayer()
						local Path = PathfindingService:CreatePath()
						local MovingToPosition = game.Workspace:WaitForChild(name):FindFirstChild("HumanoidRootPart").Position
						local ComputedPath = Path:ComputeAsync(script.Parent.PrimaryPart.Position, MovingToPosition)
						return Path
					end
					if char then
						RunService.Stepped:Connect(function()
							FollowPlayer()
							local Path = FollowPlayer()
							for _, waypoint in pairs(Path:GetWaypoints()) do
								script.Parent.Humanoid:MoveTo(waypoint.Position)
							end
						end)
					end
				end
			end
		end
	end
end 


If I am not mistaken (which I very well could be), when a player dies, the joints connecting the body parts are broken, including the one that holds up the HumanoidRootPart. Therefore, I believe that the HumanoidRootPart falls through the ground and into nothing, therefore becoming the farthest target and not being followed by the foresaid NPC.

I’d confirm this before taking my word, but one way to test my theory is to follow after the Head of the players rather than their HumanoidRootPart. Inform me of the results.

As a player dies after 5-6 seconds it deletes itself.
If it falls into the void it deletes itself aswell.