The clicking sound is the starter motor relay which is responding to the ignition switch as is should.
It sends12 volts to the starter motor. So either the wire from the relay to the starter motor is loose where it attaches to the starter or the stater motor is getting flakey. So chect the heavy gauge wire at the starter motor to be sure it is firmly attached. If so, then have a helper try the start with the ignition key when it is simply klicking the relay to determing if the starter motor might connect while you tap on the side ot the starter motor with a hamer. Ii that works then It suggests that the starter motor is at fault and needs to be replaced.