Problems with AI?

I’m trying to make my own ai program and also I have another script that jumps gaps for it, allowing it to scale obbys,
problem is my little following parkourer is a little dumb and will commonly run his face into a wall and cuz he cant see anything becomes blind, also he will be standing on a surface and when hes level with someone yeah he can see them but when that jump he can only see .001 inch of verticle up to his height so he can’t see them

and since this relies on update ticks, that means if u spam jump little buddy gets confused why the player keeps disappearing and kinda just stops caring, can anyone help rebuild the code? im not great so telling me “pump the 23y98ufwuih3ru filter to over 9000! so that he can ultimate jimmy neutron” please just rebuild it for me and I would be happy (PS if ur uber cool add some extra things I can change to make him have easy adjustable big jimmy neutron brain) ty

local NPC = script.Parent
local Humanoid = NPC:WaitForChild("Humanoid")
local HumanoidRootPart = NPC:WaitForChild("HumanoidRootPart")

local Players = game:GetService("Players")
local PathfindingService = game:GetService("PathfindingService")
local Workspace = game:GetService("Workspace")

local chaseTime = 100 -- Time in seconds the NPC will chase a player
local updateInterval = .4 -- Time in seconds between path updates

local function getNearestPlayer()
	local nearestPlayer = nil
	local shortestDistance = math.huge

	for _, player in ipairs(Players:GetPlayers()) do
		local character = player.Character
		if character and character:FindFirstChild("HumanoidRootPart") then
			local distance = (HumanoidRootPart.Position - character.HumanoidRootPart.Position).Magnitude
			if distance < shortestDistance then
				nearestPlayer = player
				shortestDistance = distance
			end
		end
	end
	return nearestPlayer
end

local function hasLineOfSight(player)
	local character = player.Character
	if character and character:FindFirstChild("HumanoidRootPart") then
		local ray = Ray.new(HumanoidRootPart.Position, (character.HumanoidRootPart.Position - HumanoidRootPart.Position).Unit * 10000)
		local hit, _ = Workspace:FindPartOnRayWithIgnoreList(ray, {NPC})
		return hit and hit:IsDescendantOf(character)
	end
	return false
end

local function chasePlayer(player)
	local character = player.Character
	if character and character:FindFirstChild("HumanoidRootPart") then
		local startTime = tick()
		while tick() - startTime < chaseTime do
			local path = PathfindingService:CreatePath()
			path:ComputeAsync(HumanoidRootPart.Position, character.HumanoidRootPart.Position)

			local waypoints = path:GetWaypoints()
			for _, waypoint in ipairs(waypoints) do
				Humanoid:MoveTo(waypoint.Position)
				Humanoid.MoveToFinished:Wait()
			end
			wait(updateInterval)
		end
	end
end

while true do
	local nearestPlayer = getNearestPlayer()
	if nearestPlayer and hasLineOfSight(nearestPlayer) then
		chasePlayer(nearestPlayer)
	end
	wait(updateInterval)
end

At a quick glance I’m noticing that you’re using wait() instead of task.wait(), wait() is deprecated so use task.wait()!