Ai Pathfinding becomes worse permanently when ai comes near player

So basically when the ai is near the player, it stops jumping, falling, climbing, and using pathfinding links. But it stills chases the player just stutters a bit (I would record the video of it happening but it lags the studio so much it is basically useless)

Script:

local PathfindingService = game:GetService("PathfindingService")
local character = script.Parent
local humanoid = character.Humanoid

local animateScript = character:WaitForChild("Animate")

local EndPoint = workspace.EndPoint2

local waypoints
local nextWaypointIndex
local reachedConnection
local blockedConnection

local walkAnimationTrack = humanoid:LoadAnimation(animateScript.walk.WalkAnim)

for _, Part in pairs(character:GetDescendants())do
	if Part:IsA("BasePart") then
		if Part:CanSetNetworkOwnership() then
			Part:SetNetworkOwner(nil);
		end;
	end;
end

local path = PathfindingService:CreatePath({
	
	AgentRadius = 2,
	AgentHeight = 5,
	AgentCanJump = true,
	AgentCanClimb = true,
	AgentJumpHeight = 7.2,
	WaypointSpacing = 4,
	Costs = {
		KillBrick = math.huge,
		JumpOver = 1,
		Climb = 1
	}
})

local function followPath(destination)
	local success, errorMessage = pcall(function()
		path:ComputeAsync(character.HumanoidRootPart.Position, destination)
	end)

	if success and path.Status == Enum.PathStatus.Success then
		waypoints = path:GetWaypoints()
		
		for i, v in pairs(workspace:GetChildren()) do
			if v.Name == "Visual" then
				v:Destroy()
			end
		end
		
		for i, Waypoint in waypoints do
			local Visual = Instance.new("Part")
			Visual.Name = "Visual"
				Visual.Size = Vector3.new(.5, .5, .5)
				Visual.Position = Waypoint.Position
				Visual.Parent = workspace
				Visual.Material = Enum.Material.Neon
				Visual.Shape = "Ball"
				Visual.Anchored = true
				Visual.Color = Color3.fromRGB(255, 255, 255)
				Visual.CanCollide = false
				Visual.CanQuery = false
				Visual.CanTouch = false
			end
		blockedConnection = path.Blocked:Connect(function(blockedWaypointIndex)
			if blockedWaypointIndex >= nextWaypointIndex then
				blockedConnection:Disconnect()
				followPath(destination)
			end
		end)

		if not reachedConnection then
			reachedConnection = humanoid.MoveToFinished:Connect(function(reached)
				if reached and nextWaypointIndex < #waypoints then
					nextWaypointIndex += 1
					if waypoints[nextWaypointIndex].Action == Enum.PathWaypointAction.Jump then
						if humanoid:GetState() ~= Enum.HumanoidStateType.Freefall then
							script.Parent.Humanoid:ChangeState(Enum.HumanoidStateType.Jumping)
						end
					end
					if waypoints[nextWaypointIndex].Label == "JumpOver" then
						if humanoid:GetState() ~= Enum.HumanoidStateType.Freefall then
							script.Parent.Humanoid:ChangeState(Enum.HumanoidStateType.Jumping)
							humanoid:MoveTo(waypoints[nextWaypointIndex + 1].Position)
						end
					else
						humanoid:MoveTo(waypoints[nextWaypointIndex].Position)
					end
				else
					reachedConnection:Disconnect()
					blockedConnection:Disconnect()
				end
			end)
		end

		nextWaypointIndex = 2
		humanoid:MoveTo(waypoints[nextWaypointIndex].Position)
	else
		warn("Path not computed!", errorMessage)
	end
end

task.wait(2)

while true do
	task.wait()
	if humanoid:GetState() ~= Enum.HumanoidStateType.Climbing then
		if humanoid:GetState() ~= Enum.HumanoidStateType.Jumping then
			followPath(workspace.MilitaryBoi1232.HumanoidRootPart.Position)
		end
	end
end