How to optimize my shooting code?

You can add a Timer node to your gun, check if the timer is stopped before shooting, and start it after shooting. This way you can change the time between bullets in the Timer’s properties. Make sure the timer is set to “One Shot”

if Input.is_action_just_pressed("Shoot") and $Timer.is_stopped():
    # etc fire bullet code...
    $Timer.start()

Make sure to paste code instead of screenshots