If they had no spears, sarissas but just pilums, a sword and a shield... They took probably take out of a few of the enemy cavalry with pilums but that wouldn't be enough.
The traditional 4 main methods they used were:
Their own cavalry protects them from enemy cavalry.
Ranged weapons. Arrows, slings, javelins, artillery.
Good defensive terrain and/or field fortifications.
Spears.
The first of these - one's own cavalry - can fail when the enemy cavalry is stronger. For a typical Roman army, it can't be depended on against a cavalry-strong enemy. In this case, the 2nd to 4th methods come into play, and the Romans are likely to be forced to fight a defensive battle.
The second and third are related. Good defensive terrain or fortifications will give the Romans the chance to use their ranged weapons.
The fourth of these can be put into action by using pila as thrusting spears.
Arrian's Array against the Alans prescribes 2 through to 4 (the Roman cavalry was too weak to stop the Alanic cavalry, and was to be held in reserve to pursue the Alans if they broke and fled). The planned battle array is described:
Each wing of the infantry should hold high ground, as the full deployment must be in this order. On the right flank should be deployed the Armenians with Vasakes and Arbelos, holding the highest part of the flank, because they are archers all. Positioned in front of them must be the infantrymen of the Italian regiment. In command of all these should be Pulcher, who is in charge of the Italian regiment. Both Vasakes and Arbelos with their cavalry and infantry should be arranged in support of him.
First, good defensive terrain, making use of high ground, is to be used. Archers are to be protected by other infantry (and/or cavalry).
On the left flank the Allies from Lesser Armenia an the light armed from Trapezus and the Rhizian javelinmen should be arrayed holding the highest part of the flank. Deployed to their front must be the two hundred Apulians and a hundred of the Cyrenaicans, in order that the heavy armed are a bulwark for the javelineers, they can hurl their javelins overhead from the high ground.
Similarly, javelineers are to be protected by other infantry.
The Fifteenth Legion’s infantry should hold the entire right center above the middle of the whole area, because they are by far the most numerous: the infantrymen of the Twelfth Legion should hold the remaining space on the left filling it up to the point of the left flank. They should deploy in eight ranks and their deployment should be close ordered. And the front four ranks of the formation must be of spearmen, whose spearpoints end in thin iron shanks. And the foremost of them should hold them at the ready, in order that when the enemies near them, they can thrust the ironpoints of the spears at the breast of the horses in particular. Those standing in second, third an fourth rank of the formation must hold their spears ready for thrusting if possible, wounding the horses and killing the horsemen and put the rider out of action with the spear stuck in their heavy body armour and the iron point bent because of the softness. The following ranks should be of the javelineers. The ninth rank behind them should be the foot archers, those of the Numidians, Cyrenaicans, Bosporans and Ityraeans.
The legionaries hold the centre, and the front ranks are to use their pila as thrusting spears. Those to the rear are to use them as javelins (or to use other javelins?). Behind them, archers.
Artillery pieces must be deployed on each flank to fire at the advancing enemies at maximum range, and behind the whole battle formation.
Artillery is deployed where they can shoot over the infantry. This is one of the important functions of defending high ground - javelineers, archers, and artillery can more effectively shoot over the infantry in front, since they can be placed higher, providing them with better visibility and more range.
The entire cavalry arrayed together in eight wings and squadrons must stand next to the infantrymen on both flanks, having the heavy armed and archers as a screen, two companies and in the middle of the formation six companies [ Gap in text ] the horse archers among them must form close to the battle line in order to shoot over it. The javelineers, spearmen, swordsmen and axe-men must guard both flanks and await the signal.
The cavalry is kept in reserve, protected by infantry. Mounted archers will shoot over the protecting infantry.
How was the battle expected to proceed? Arrian continues:
Once thus arrayed there should be silence until the enemies come within missile range; when in range the loudest and most intimidating war cry must be raised by the whole lot, and bolts and stones must be fired from the artillery pieces and arrows from the bows, and javelins by both light armed and shield bearing javelinmen. Stones must also be thrown at the enemies by the allied force on the overwatch position, and the whole missile rain must be coming from all sides to make it concentrated enough to panick the horses and destroy the enemies. And the expectation is that the Scythians will not get close to the infantry battle formation because of the tremendous weight of missiles.
Explicitly, the expectation is that firepower will stop the Alanic cavalry, Arrian's "Scythians", before they get in close.
If they do close in though, the first three ranks should lock their shields and press their shoulders and receive the charge as strongly as possible in the most closely ordered formation bound together in the strongest manner. The fourth rank will throw their javelins overhead and the first rank will stab at them and their horses with their spears without pause.
But if they aren't stopped by firepower, the infantry receive the charge in close order formation. Their pila are to be used as spears to stop them, while the javelineers, archers, and artillery keep up their fire.
After repulsing the enemy if there’s a clear rout, the infantry units must clear lanes and the horsemen should advance, not all squadrons, but only half of them. Those to the fore must be the first to advance. The other half should follow those that advance, in perfect formation and not in hot pursuit in order that they may continue the initial pursuit with fresh horses in case there is a complete rout, and in case they turn about to attack, they may assist those in pursuit. At the same time the Armenian archers must advance shooting their bows in order to prevent those in flight from turning about, and the light armed javelineers should advance at the run. The infantry formation should not hold its ground, but should advance at faster than the normal step in order to be a base of defence for the cavalrymen if there is stronger resistance by the enemies.
If the Alans break when their charge fails, the Romans are to pursue. Now the Roman cavalry comes into action, with half pursuing at speed, and the other half following to provide support, maintaining good formation. This will (hopefully) stop disaster if the retreat is feigned.
These things should happen if they are put to flight after the first charge. If they about-face and circle around the flanks, the flanking bodies of lightly armed archers should extend formation to the high ground. I do not think that seeing that the flanks become weaker through extension in this manner they will break through them and cut up the infantry. Should they overcome one or either of the flanks the horses would necessarily expose their flanks, their spears at a right angle. In that case the cavalrymen must attack not with a missile shower but with swords and and axes. The Scythians being lightly armed and having unprotected horses [text breaks off ]
If none of those things work - if the Alans aren't stopped by firepower, and they don't break when their initial charge fails, they are likely to attempt to turn the flanks. Now the Romans need to depend on steady discipline, taking advantage of the terrain, and be prepared to counter-attack any penetration of their flanks.
Note the last words: "unprotected horses". This makes the arrows, slingstones, and javelins much more effective. Cavalry with armoured horses will make the Roman's task more difficult. Armoured cavalry - with armoured horses - are much more likely to successfully get through the ranged fire, and close with the infantry. The lack of long spears (pila can be used as spears, but they are relatively short, and might not out-reach enemy lances) can make it difficult for the legions to stop the cavalry. Depending on numbers and terrain, the final result might be quite unfavourable - the Romans did lose against such armies, and sometimes quite badly.
The other problem the Romans have is being forced into a defensive battle. Against a cavalry force, to use good defensive terrain, they must remain in place. If the enemy decides to not attack, what do the Romans do? If the enemy doesn't attack because the Roman defensive position is too strong, they will have the options of attacking the Romans in more favourable terrain if the Romans advance towards them. If the Romans are too strong even in that case, they can avoid fighting, perhaps resorting to scorched earth tactics to try to weaken the Romans. Even if the Romans are strong enough to be likely to win a battle, victory in the war can be difficult. Steps 2-4 above are neither guaranteed to win battles nor guaranteed to win wars.
If it is just legionaries, without any friendly cavalry, without supporting archers and light infantry, then they would have a really big problem, unless the enemy cavalry force is very weak. In this case, it can come down to a simple choice for the Romans: die bravely, or surrender.