Help with pathfinding

  1. I would like to edit my weeping angel module to use pathfinding and what not but I have no experience with such topics it also runs every frame so im trying to optimise it for performance

  2. Every time I try it either lags with the simplepath module or it doesnt pathfind correctly zigzagging on terrain and what have you and also staying stuck on walls.

function weepingAngelModule:update()
	local isSeen = false
	local closestPlayerDistance = 1000
	local closestPlayerPosition = nil

	for i, player in pairs(weepingAngelModule.players) do
		if player[2] == nil then
			continue
		end	
		local character = player[1].Character
		local humanoid = character:FindFirstChild('Humanoid')
		local humanoidRootPart = character:FindFirstChild('HumanoidRootPart')

		if humanoidRootPart == nil or humanoid == nil then
			continue
		end
		if humanoid.Health == nil then
			continue
		end

		fauxCamera.CFrame = player[2]
		fauxCamera.DiagonalFieldOfView = player[3][1] * 2
		fauxCamera.FieldOfView = player[3][2] / 2
		fauxCamera.MaxAxisFieldOfView = player[3][3] / 1
		local position, isOnScreen = fauxCamera:WorldToViewportPoint(self:getPosition())
		if isOnScreen then
			isSeen = true
			break
		end
		local plrPosition = humanoidRootPart.CFrame.Position
		local playerDistance = (self:getPosition() - plrPosition).Magnitude

		if playerDistance < closestPlayerDistance then
			closestPlayerDistance = playerDistance
			closestPlayerPosition = humanoidRootPart.CFrame.Position
		end
	end

	if isSeen == false and closestPlayerPosition then
		self.humanoid.WalkSpeed = 12
		self.moveToPosition = closestPlayerPosition
	else
		self.moveToPosition = self:getPosition()
		self.humanoid.WalkSpeed = 0
	end

	local path = pathfindingService:CreatePath({
		AgentRadius = 6,
	})
	local succ, err = pcall(function()
		path:ComputeAsync(self.humanoidRootPart.Position, self.moveToPosition)
	end)
	if succ and path.Status == Enum.PathStatus.Success then
		local waypoints = path:GetWaypoints()
		for _, waypoint in waypoints do
			self.humanoid:MoveTo(self.moveToPosition)
			self.humanoid.MoveToFinished:Wait()
		end
	end
	--
end