I selected that slot 2 of the AMS should be used, instead slot 4 was used. one is black PETG and one is white PETG.
As there’s not a lot of information in your posting, let me guess: You set up the colors in the bar on the left of the slicer and then selected the color you wanted for your object?
That is not where AMS slots are selected. The numbers are not AMS slots, they are just the filaments in your project.
The mapping of filaments to AMS slots is actually done in the dialog box when you send the print:
You can select any slot with the same filament type, and if you select the wrong one it will happily print with a different color.