I tried to set the backup preference to Primary but it doesn't change, it stays on Prefer Secondary
I'm not sure if you mean the user interface, or if the actual effect of the change didn't occur as you expected. My answer assumes the latter.
To be clear about something that I find a little confusing: this setting is not something that automatically affects how backups are run. It's simply a place where you, as a DBA, can store "metadata" about how you prefer backups to be taken.
This is documented, but it's not obvious at all from the user interface. Here's the quote from the docs:
There is no enforcement of the AUTOMATED_BACKUP_PREFERENCE setting. The interpretation of this preference depends on the logic, if any, that you script into back jobs for the databases in a given availability group. The automated backup preference setting has no impact on ad hoc backups.
After setting this, you need to update your backup jobs with code like this (also lifted from the docs):
IF (NOT sys.fn_hadr_backup_is_preferred_replica(@DBNAME))
Select 'This is not the preferred replica, exiting with success';
RETURN 0 - This is a normal, expected condition, so the script returns success
BACKUP DATABASE @DBNAME TO DISK=<disk>
sp_helptext to view the source of
sys.fn_hadr_backup_is_preferred_replica, it can be seen that this takes into account both the AG-level
AUTOMATED_BACKUP_PREFERENCE setting, and the replica-level
Note: since you're using Ola's scripts, this is already taken into account
If you just didn't see the value change in the user interface, I would suggest using the "script" button to show the T-SQL that's being run by the UI, and then running that script manually to see if the change is properly made.