You can create a Virtual LayerVirtual Layer. Replace "color"
with the name of your color field and 'Random points'
with the name of your layer:
select *,
row_number() over(partition by "color") as "SERIAL"
from 'Random points'
A new temporary layer will be created which you can right click and save: