Just in addition to the other posters, backup if you haven't already. To start, you need an external hard drive. Here’s a few excellent ones sold by Apple:
If you have an iMac (Late 2015) or earlier, or a Mac mini (Late 2014) or earlier, you will also need this cable.
You can then follow the steps in this Apple Support article to setup your Time Machine backup: Back up your Mac with Time Machine - Apple Support.
Also, moving forward, I recommend that you use iCloud in addition to Time Machine to sync all your files and photos to all your Apple devices. Although iCloud is not a "true" backup service, iCloud can also act as an emergency off-site backup, but this is why iCloud should be used in addition to Time Machine. Here are some resources on setting up iCloud for Mac:
After you setup iCloud, turn off "Optimize Mac Storage" in System Preferences > Apple ID/iCloud. That way, all changes made to files in iCloud are also backed up to Time Machine. If you have this setting on due to a limited amount of storage on your Mac, that is fine. Just know changes won't be backed up to Time Machine, only iCloud.
Next, because your Mac is obsolete, Apple cannot repair your Mac, unfortunately. So, this means that you'd need to replace your Mac. You could get a Mac mini - Apple or a Mac Studio - Apple, with a Studio Display - Apple, or look here for 27-inch iMac computers: Certified Refurbished Products - Apple. Here are all the new Mac computers Apple sells: Mac - Apple.
Jack