Dynamicly Changing Snapping Base Help

Sorry for the absolute worst title I wasnt exactly sure on how to explain what I’m after

Basically I’m trying to build a tile based building system of sorts and I’m trying to understand the base way to achieve it, I have a quick and dirty version here to show you what im trying to achieve:

as you can see in that video I’ve made it so you can spawn in extra tiles to sort of expand the base but as you can tell theres a lot of extra walls and stuff as i havent figured out a way to change the mesh based on the adjacent pieces.

Just for more reference here is a video of what im trying to recreate from an old game:

Any help or information on how i can achieve that type of building system would be great
(I’ve heard of sockets and stuff but im not entirely sure if how that works or if its the right option for this) Thanks!