Problem with this randomly generated corridor

I managed to make this corridor generate properly but now, when I try generate the “start” it overlaps and generates the wrong way round.

It has a part in it called “Begin”(not to be confused with the other one in Workspace) where the sections are meant to spawn(they have different pivots than their centre)

And the overlapping doesn’t happen with anything but this start section. Why is this happening?

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local segments = ReplicatedStorage.Segments:GetChildren()
local starts = ReplicatedStorage.Starts:GetChildren()
local ends = ReplicatedStorage.Ends:GetChildren()

local segment_tables = {}

local max = 10

local cooldown = 0

function ChooseSegment(): Model
	local random = segments[math.random(1, #segments)]
	table.insert(segment_tables, random)
	return random
end

function ChooseStart(): Model
	local random = starts[math.random(1, #starts)]
	local clone = random:Clone()
	clone.Name = "Start"
	clone.Parent = workspace
	return random
end

function ChooseEnd(): Model
	local random = ends[math.random(1, #ends)]
	return random
end

local part = workspace.Begin

function PositionSegment(segment: Model)
	local clone = segment:Clone()
	clone:PivotTo(part.CFrame)
	clone.Parent = workspace
	
	part = clone.End
end



local counter = 0

repeat PositionSegment(ChooseSegment()) task.wait(cooldown) counter+=1 until counter >= max

ChooseStart():PivotTo(segment_tables[1].Start.CFrame)
2 Likes

Rotate the pivot of the start 180 degrees.
should fix it.

3 Likes