Hadithcore
Al-Adab Al-Mufrad, 70
sahih· Al-Albani

Hakim ibn Hizam said to the Prophet, (ﷺ), "Do you think that the acts of worship which I used to do in the time of the Jahiliyya - maintaining relations with relatives, setting slaves free and sadaqa - will bring me a reward?" Hakim said that the Messenger of Allah, (ﷺ), said, "When you become Muslim, you keep the good actions you have already done."

حَدَّثَنَا أَبُو الْيَمَانِ، قَالَ‏:‏ أَخْبَرَنَا شُعَيْبٌ، عَنِ الزُّهْرِيِّ قَالَ‏:‏ أَخْبَرَنِي عُرْوَةُ بْنُ الزُّبَيْرِ، أَنَّ حَكِيمَ بْنَ حِزَامٍ أَخْبَرَهُ، أَنَّهُ قَالَ لِلنَّبِيِّ صلى الله عليه وسلم‏:‏ أَرَأَيْتَ أُمُورًا كُنْتُ أَتَحَنَّثُ بِهَا فِي الْجَاهِلِيَّةِ، مِنْ صِلَةٍ، وَعَتَاقَةٍ، وَصَدَقَةٍ، فَهَلْ لِي فِيهَا أَجْرٌ‏؟‏ قَالَ حَكِيمٌ‏:‏ قَالَ رَسُولُ اللهِ صلى الله عليه وسلم‏:‏ أَسْلَمْتَ عَلَى مَا سَلَفَ مِنْ خَيْرٍ‏.‏

References2 variants
In-Book Reference
Book 2, Hadith 24
English Reference
Book 2, Hadith 70