How To Make Parts Detect If They Will Be Colliding Before Even Being Cloned

  1. What do you want to achieve?
    So It Detects If There Will Be Collision Between Parts Before They Even Will Be Cloned And If It Will Than It Will Put Other Part That Will Not Collide And If Not Able To Just Do Nothing
  2. What is the issue?
    I Don’t Know How To Do It
for i = 1,100 do
	for i,v in pairs(game.Workspace.Maze:GetChildren()) do
		local attachment2 = v:FindFirstChild("Attachment")
		
		for i,v in pairs(v:GetChildren()) do
			
		end
		if attachment2 ~= nil then
			newpart = game.ReplicatedStorage.MazePart:Clone()

			local attachment2 = v.Attachment
			newpart.BrickColor = BrickColor.random()
			newpart.Parent = game.Workspace.Maze

			local attachment1 = newpart.ConnectionAttachment
			newpart.CFrame = attachment2.WorldCFrame * attachment1.CFrame:Inverse()
			attachment2:Destroy()

			wait(0.125)			
		end		
		end
			end

this is the code i am gonna make it so it gets diffrent fragments but 1st i need to make it so it prevents collision
3. What solutions have you tried so far?
I Have Tried Asking A Coder Friend And Looked Up On Google With No Success
btw this is what it basicly does

1 Like

use Raycast to detect if there is any part

local RayOrigin = Attachment.WorldPosition
local RayDirection = Attachment.WorldCFrame.LookVector

local Length = newpart.Size.X

local result = workspace:Raycast(RayOrigin, RayDirection * Length)

if result then
	print("There is a part")
end

Try making an invisible part of the same size and position and checking if there’s anything there, and if not, cloning the original part there.

thx it helped alot now i can readd the randomize sections and boom im done.