It is narrated from Jabir (may Allah be pleased with him) that he said: A man from the tribe of Banu Udhrah made his slave a Mudabbar (a slave who is set free after the master's death). When the Prophet (ﷺ) was informed, he asked: "Do you have any wealth besides him?" He replied: "No." Then the Messenger of Allah (ﷺ) said: "Who will buy this slave from me?" Na’eem bin Abdullah Al-Adawi (may Allah be pleased with him) bought him from the Prophet (ﷺ) for eight hundred dirhams. He brought the amount to the Prophet (ﷺ), and the Prophet (ﷺ) handed over the price to the owner. Then he said: "Start with yourself and spend on it. If anything is left from yourself, then on your family. If anything is left from your family, then on your relatives. If anything is still left, then here and there, to the right and left (i.e., to other deserving people), spend it."
Hadith Referenceمسند الإمام الشافعي / كتاب العتق والولاء والمدبر والمكاتب وحسن الملكة / 1094
Hadith Takhrijاخرجه مسلم ، الزكاة ، باب الابتداء في النفقة بالنفس ثم اهله ثم القرابة (997)۔