keep both the 3DS close in front of one another and away from obstruction to ensure it can connect easily, make sure you're connecting to the right person.
this doesn't sound like the solution, considering you are also having issues with the internet, when you say you are connecting locally, are you saying you are connecting to someone via wireless connection directly to the other 3ds system or using the internet to send the data to space and back to the 3ds one meter away? because if it is the latter it might be an internet issue, but is probably isn't.
is this a problem that is only with S/M? does it fail to work on both 3DS? if it can do internet connection on one 3DS but fail to work on the other than it might be a 3ds issue, if neither 3DS work with either game and they work with other games (such as XY or B2/W2) than the problem might be with the game, not the 3DS.
long story short, do a few tests, see the specifics of the problem, the conclusion I came to at the moment is there is a problem with your 3ds/2ds. Did it suffer any damage, did you drop it? or maybe vomit on it (it might have happened to me) that might have damaged it's wireless system, otherwise maybe the settings on your system might have been adjusted by accident, resulting in wireless connection being disabled, so definately double check that.
if the problem is physical damage, then maybe the warrenty on the 3DS/2DS will be able to fix it, I dunno, and if the issue is with the game card(s), then the same applies I think. I am not an expert on this stuff, but yeah, experiment and see what the problem is exactly.
totally didn't vomit on my ds lite,
yours indubitably.