Ok thank you for the info
ill try to find a 6th or 7th gen cpu
Honestly it's probably not worth looking at 6th or 7th gen CPUs now. The 6th and 7th gen Core i5s only have 4 cores and 4 threads and thus tend to perform poorly in more modern workloads. The Core i7s offer 4 cores and 8 threads and are still somewhat viable, but they still tend to be quite pricey on the second hand market.
You're probably better off just getting a new CPU and motherboard entirely, the RAM could be carried over into a new build, though if it is slow DDR4 eg. 2133MHz it might not be great if you go for an AMD system.