Window cutter parts overlapping

so im trying to do a script that makes a hole in a wall and the window can fit into that hole. The problem is that my script works fine for one window but if i try to run it with second window the parts overlap on each other. I have no idea how to run the function so that the parts dont overlap.



local function config(wC)
	wC[1].Name = "wC"
	wC[2].Name = "wC"
	wC[3].Name = "wC"
	wC[4].Name = "wC"
	local up = wC[1]
	local down = wC[2]
	local left = wC[3]
	local right = wC[4]
	
	return up,down,left,right

	
end




function create.resPos(wC, win, canv)
	
	local up, down, left, right = config(wC)
	local distanceX = canv.Size.X - win.Size.X
	local distanceY = canv.Size.Y - win.Size.Y
	local offSetX =   win.CFrame.X - canv.CFrame.X 
	local offSetY =	  win.CFrame.Y - canv.CFrame.Y
	
	
	up.Size = Vector3.new(canv.Size.X - distanceX, math.clamp(distanceY / 2 - offSetY,0,canv.Size.Y), canv.Size.Z)
	up.CFrame =  canv.CFrame * CFrame.new(offSetX, canv.Size.Y / 2 - up.Size.Y / 2, 0) 
	
	down.Size = Vector3.new((canv.Size.X-distanceX),math.clamp(distanceY / 2 + offSetY,0,canv.Size.Y),canv.Size.Z)
	down.CFrame = canv.CFrame * CFrame.new(offSetX,-canv.Size.Y/2+down.Size.Y/2,0)
	
	left.Size = Vector3.new(math.clamp((distanceX/2)+offSetX,0,canv.Size.X),canv.Size.Y,canv.Size.Z)
	left.CFrame = canv.CFrame * CFrame.new(-canv.Size.X / 2 - -left.Size.X / 2,0,0) 
	
	right.Size = Vector3.new(math.clamp((distanceX/2)-offSetX,0,canv.Size.X),canv.Size.Y,canv.Size.Z)
	right.CFrame = canv.CFrame * CFrame.new(canv.Size.X / 2 - right.Size.X / 2,0,0)
	
	
	if right.Size.X<0.06 then
		local OverlapForumula = math.clamp((((canv.Size.X/2)-canv.Size.X - math.abs(offSetX)) + (win.Size.Z/2)),0,500)
		



		up.CFrame = up.CFrame * CFrame.new(-OverlapForumula/2,0,0)
		up.Size = Vector3.new((up.Size.X-OverlapForumula)+0.07,up.Size.Y,up.Size.Z)
		down.CFrame = down.CFrame * CFrame.new(-OverlapForumula/2,0,0)
		down.Size = Vector3.new((down.Size.X-OverlapForumula)+0.07,down.Size.Y,down.Size.Z)
	end


	if left.Size.X<0.06 then
		local OverlapForumula = math.clamp((((canv.Size.X/2)-canv.Size.X - math.abs(offSetX)) + (win.Size.Z/2)),0,500)
		



		up.CFrame = up.CFrame * CFrame.new(OverlapForumula/2,0,0)
		up.Size = Vector3.new((up.Size.X-OverlapForumula)+0.07,up.Size.Y,up.Size.Z)
		down.CFrame = down.CFrame * CFrame.new(OverlapForumula/2,0,0)
		down.Size = Vector3.new((down.Size.X-OverlapForumula)+0.07,down.Size.Y,down.Size.Z)
	end
	return up,down,left, right
end
1 Like

i did it myself by checking parts overlapping after creating them all.

set your solution as the answer then

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.