I'm making a simple dark sensor project with a light dependent resistor (LDR) and I want to replace the LED with a buzzer but it doesn't work
First, delete R2.  The buzzer has inherent current limiting, so an external resistor does nothing but reduce the volume.
Second, I think the value of R1 is so high that it is &quot;starving&quot; the transistor.  If you decrease the value of R1 it will help, but might not be enough.  The problem is that for the BC547, R1 does not allow enough base current so the transistor can sink 30 mA.
But there is another issue.  When you decrease R1 it changes the amount of light (or darkness) that activates the buzzer.  If 50 K is the right value for your light levels, then you need to change the transistor to either a darlington type or a MOSFET.