Some useful past discussion of this by u/When_Ducks_Attack and u/eighthgear and u/Domini_canes in https://www.reddit.com/r/AskHistorians/comments/33sa2x/effectiveness_of_shipborne_antiair_in_wwii/
In that discussion, it's noted that a little over 1/3 of the enemy aircraft that attacked US warships and came into range of their anti-aircraft guns were shot down by those guns. The USN had excellent fire control systems for their AA guns, with effective radars and the best (analog) computers of the time. Their ships had plentiful AA guns, and they threw up a large volume of fire at attackers.
How effective was this - the best naval AA fire of the war? 2/3 of attacking aircraft were not shot down, and about 10% of attacking aircraft hit ships. Aircraft that were shot down before attacking failed to hit, and aircraft under heavy AA fire were more likely to miss.
Reducing hit rates to 10% isn't enough, if enough aircraft attack. The Japanese hit Prince of Wales and Repulse with about 10% of their bomb attacks, and about 10% of their torpedoes in their initial attacks (with more torpedo hits after the initial hits slowed down the ships). On the other hand, it's better than nothing. With no AAA, air attacks can be very accurate and effective. Reducing the hit rate to 10% can be the difference between being damaged and being sunk.