Gap filling struggles

Hello!

So I’m having this issue with my wall system where I am trying to fill a gap but it’s very frustrating because sometimes the part that’s created doesn’t orient right and causes it to look even uglier. Could someone help?

I’ve tried a few things:

1- find the intersection and create a part that’s 0.5 thick but the width is the same as the difference between the gap if that makes sense.

Code:

    local fillerPartPoint1 = plot.CFrame:ToWorldSpace(CFrame.new(intersectingWallPoint1.Value) * CFrame.Angles(outerWall1.CFrame:ToOrientation())) * CFrame.new(-0.25,0,0)
	local fillerPartPoint2 = plot.CFrame:ToWorldSpace(CFrame.new(intersectingWallPoint2.Value) * CFrame.Angles(outerWall2.CFrame:ToOrientation())) * CFrame.new(-0.25,0,0)
	local plate = Instance.new('Part')
	plate.Position = plot.CFrame:PointToWorldSpace(intersectingWallPoint1.Value)
	plate.Orientation = (outerWall1.Orientation + outerWall2.Orientation) / 2
	plate.Size = Vector3.new(0.5, 10, (fillerPartPoint1.Position - fillerPartPoint2.Position).Magnitude)
	plate.Anchored = true
	plate.Parent = outerWall1

Result (note the small misalignment):
Screen Shot 2021-09-08 at 8.39.20 PM
2- find the position between the 2 gaps and make a part, then offset the CFrame by -0.25

Sizing works for the most part but sometimes the part is moved wrongly.

    plate.Position = (fillerPartPoint1.Position + fillerPartPoint2.Position) / 2
	plate.CFrame = CFrame.lookAt(plate.Position, fillerPartPoint1.Position)
	plate.CFrame *= CFrame.new(-0.25,0,0)
	plate.Size = Vector3.new(0.5, 10, (fillerPartPoint1.Position - fillerPartPoint2.Position).Magnitude)
	plate.Anchored = true
	plate.Parent = outerWall1

Result sometimes:

Result at other times (which is what I want to achieve)

Any ideas?

Feel free to test it out, use the Create Wall button:
ok.rbxl (36.5 KB)

Solved it!

It uses the second method and compares the magnitude from the destination to the intersection, whatever is closer is what’s chosen.

Glad you were able to get this resolved. I wanted to point you to a plugin that my partner and I use and love. It is called Stravant - GapFill & Extrude. The link is to the original plugin, so it is safe to use. I am sure there are others, but I have experience with this and Stravant has a great reputation.

Stravant has many great plugins.

Yeah, I had a look at the source code and I wasn’t really able to understand it. My solution seems to be as reliable as I can get it.

Hey, sorry for necroposting, I’m just curious about how did you solve it, I can’t understand what you meant in the original reply.

Already made a method to do it by myself, I will still be happy if you can explain me how did you solve it as I don’t know if my code is clean Filling gap for walls in live-game