How to prevent randomly generated plot from blocking itself

Recently had the idea of adding randomly generated dungeons inside of my game through plots, thing is i dont know how to make it check if there’s a wall in front of it or not, i know you can use rays but every attempt i’ve made with rays returns everything it goes through as nil, if someone knows how to do this it would be highly appreciated.

Code
local Plots = game:GetService("ServerStorage"):WaitForChild("Assets").PBGPlots:GetChildren()

local Folder = workspace.Generated

local PreviousPlot = Folder:WaitForChild("Regular0")

local ChosenPlot = nil

for i = 1,15 do

if i == 1 then

ChosenPlot = Plots[1]

else

ChosenPlot = Plots[math.random(#Plots)]:Clone()

end

ChosenPlot.Name = ChosenPlot.Name..i

ChosenPlot:SetPrimaryPartCFrame(PreviousPlot.Connector.CFrame)

ChosenPlot.Parent = Folder

PreviousPlot = ChosenPlot

end

(this code doesnt have any ray stuff in it btw, none of my previous attempts worked)

You could possibly limit each segment to being a certain size (say 100x100 studs wide), and then space the plots out over 100 studs

the plots i’ve made are designed to make random turns, and they sometimes just do a full loop and block eachother.

What do you mean by random turns? Could you give a diagram?

there is a “turn” plot that is randomly selected and a “regular” plot that is randomly selected aswell, the “turn” plot is a simple turn, and the “regular” is just a hallway.

So you need to connect all of these plots?

yes, all plots have a root and a connector, the root’s cframe is set to the connector and so on, but i want to make it so it doesnt do a loop and block itself

Well what I would do is for each connector, make a value or some way to tell if a turn has been created there, and then if it tries to create another turn, either don’t make one or flip the turn the other way

Still nothing, it keeps blocking itself off

Mind showing the script?