You are not eligible to receive dividends if you buy shares on ex-date, you will be eligible only if you buy before ex-date.
Buyer of the shares is not eligible to receive dividends if bought on ex-date, while seller of the shares on ex-date will be eligible to receive dividends.
So the dividends received will be passed on to the seller of the shares.