Delete all render files, then turn off background rendering if on (in FCPX preferences). Do a fresh one-time pre-render of the entire timeline by selecting all clips via CMD+A, then render all with CTRL+R. That helps isolate a render vs encoding problem.
Make sure all volumes have plenty of free space. Run Disk Utility First Aid on all volumes. For the boot volume this requires starting in recovery mode (boot while holding CMD+R).
If exporting to a network drive or through a hub, try exporting to a local directly-connected drive. Make sure that drive is HFS+ or APFS not ExFAT.
Make sure you are not running Chrome. That can cause various FCPX performance and stability problems.