So according to descriptions of the Roman maniple system, each individual maniple of hastati would be separated from the other by an empty space roughly the same size of the maniple itself. The principes maniples would position themselves behind that empty space, and the same with the triarii. Thus creating a checkerboard formation.
But how did the enemies react to the many empty spaces between each maniple? I guess a phalanx would not attempt to exploit them as it would mean breaking formation, but what about the Gauls or samnites which, to my understanding, weren't deployed as phalanxes.
A key reason why Romans were able to maintain gaps between their maniples was the fact that they were in fact very dangerous places to go. Let us suppose that a syntagma, a 64 man unit of Macedonian pikemen, wanted to enter the gap between two maniples of hastati. Suddenly, they find themselves in a very unpleasant situation. To their front is a maniple of the principes, who are throwing javelins at them. On either side, the hastati are also throwing javelins at them, creating a lethal crossfire. Especially dangerous are the hastati on the right flank, probably 6-8 men deep, who can rake the syntagma with javelins on the unshielded side. Not only that, but as soon as any phalangites fall, Romans are authorized to run out of their formation "in order to save a citizen, retrieve a weapon or strike an enemy," (Livy 22.38.4) which means that any sudden space within the formation is going to be filled with an enterprising Roman swordsman or two. So for a syntagma to rush into the 10-15 gap between two maniples is less exploiting a weak point than plunging into a sausage machine.
While I've used a phalanx syntagma in this example, and its by far the most vulnerable formation as the query points out, but the same would apply to a band of Gallic warriors or a maniple of Samnites. Entering the gap with the Romans in good order would mean exposing both flanks and facing a very fresh enemy to the front, all the while caught in three-way javelin crossfire.
Also, it should be noted that these gaps were never entirely empty. Sometimes archers and slingers were stationed between maniples (e.g. Sallust Iug. 49.6) . Sometimes one might find war elephants there when the Romans deployed these animals after the Second Punic War. It would not be surprising if some velites lingered in between the gaps between the hastati hoping for one more kill even after they withdrew form the front.
Further reading:
M. Taylor, 2014: "Roman Infantry Tactics in the Mid-Republic" Historia 63, 301-322.
P. Johstono and M. Taylor 2022. "Reconstructing the Battle of Pydna." GRBS 62, 44-76.