I get an error sound/error message about duplicates when using the scripts.

You have more than one of the same weapon in your inventory when trying to use the toggle scripts. E.g: You have 2 AR-15’s in your inventory. This a game engine limitation that we cannot fix.

To get around the issue, build the Prototype Vending Machine at a settlement & “buy” a [MF Custom] version of the weapon(s) you use. These MF Custom weapons have a different base FormID from the normal MF weapons you loot, and therefore won’t conflict with them when using the scripts. You also cannot have 2 of the same MF Custom weapons (E.g. 2 MF Custom AR-15’s), though. They will conflict the same way.