So Riker has his typical philosophically judgemental line about how these people were so afraid of death, they condemned themselves to this eternal prison. (Message!) And they examine the statues and whatnot without imagining that the statues are examining them back. They search more of the planet, trying to find someone, anyone who wasn't converted. But all they find are these statues, lined up on an intersecting grid crisscrossing the planet's surface. Of course the statues are using some kind of energy frequency thingie to communicate that the Feds don't scan for, so they never realize these things are lined up because they're networked. (Dun Dunn DUNNNN!)
So crew are back on the Enterprise when something materializes onboard. It's basically the equivalent of a mechanical rabbit. But it bites one of the NPCs (harvesting genetic material) and then transports off the ship. So now the Feds are thinking these things are possibly hostile. Rumor spreads onboard and when the next thing appears (a hovering helicopter thingie, kind of like a baddie from MegaMan), a different NPC shoots it out of panic. So now they're thinking we're hostile. So now the invasion begins. These floating platforms start transporting to the enterprise as rapidly as they can be autofac'd, and now they have beam weapons. The Enterprise quickly raises shields as Worf, Data, and Riker lead teams to eradicate the invaders. Initially, they wanted to capture at least one for examination, but they proved unable to be disabled safely (as they were auto-repairing).
Data's team is the last to find their swarm and by then the machines have begun to harden themselves against phaser fire (no shielding tech yet). Data of course figures a way to concentrate the fire and blah blah to destroy them anyway. Buuuuut then the Swirly Energy Thing drifts to the planet, intersecting the surface as well as the Enterprise. So there's now a portal to the decks of the Enterprise stretching in a giant arch on the surface of the planet. So these critters can get onboard without being fussed by the shields and they start invading the Enterprise. A few panicked crew members are surprised by the portal and end up on the planet's surface as they run from electronic pursuit. Picard doesn't want to lower the shields to beam them up because then the gizmos could beam onboard anywhere in the ship, whereas right now, they're limited to coming through the portal. So he has Data, who's closest to the portal, take his security detail to retrieve the planetside crewmembers. Meanwhile, Worf and crew make their way down to the portal-breach to maintain a pinch-point to keep too many of the invaders from coming in.
Data, who's normally pretty fearless with his tough android chassis, realizes after almost being hit with one of these platforms as it's plunging out of the sky that he's dealing with his mechanized match and so has to be careful. So of course they harvest all the missing crewmembers and make their way back to the arch-portal where Data and Worf's teams join forces to hold off the onslaught long enough that the Enterprise can widen the portal enough that they can get back to Feddie space (and time). Data has a near-miss at the mouth of the portal that leaves the back of his uniform singed, and the Feds pull back in preparation for warp. Just as they're pulling away, the last creature from the planet's surface passes through the portal. And now we see the first recognizably humanoid Borg for a few moments before it's vaporized. Because, you see, they had seen us ambulatory humans and become jealous(?) of our freedom and so worked out a way to free themselves from their metal prisons and regain some shred of humanity. And so we (in a way) created them! (clichéd plot twist!)