I just watched a video on youtube showing ryzen 5 3500x gives a better fps playing games than ryzen 7 2700 which has more cores and threads. What cores and threads really are for and which is a better cpu
Generalizing it for software in general, software can spawn separate tasks, called threads, that can be worked on independently. These tasks can be assigned to CPU cores. If a CPU core has additional hardware support, it can take on another task to work on in parallel. A key point though, is that for these tasks to run in parallel, they have to actually be able to run. So if a program has a task to load data from storage and another task to process that data, the processing task can't run because it's waiting for the load data task to be finished.
In addition, processors of different generations may be built with different implementations of how to run programs. Sometimes these implementations work better than others. In the case of the Ryzen 3500X and the Ryzen 2700, the 3500X was made with an implementation that clock-for-clock, performs better. This implementation affects the per-core performance (often referred to as single-thread performance)
Games are usually built such that their general tasks, like handling input, processing game logic, and compiling how to render the scene, run one after another. The tasks themselves may have many sub-tasks that can run in parallel, but overall, there's still an order of doing things. So games often don't scale as well as say a video encoder, which means that a processor with strong per-core performance often beats another processor with more cores when it comes to games.
EDIT: Would also like to point out that clock speed also can be a factor, but it has to be used in conjunction with per-core performance.