RRG script
local Rooms = workspace.Rooms
local previousRoom = workspace.StartRoom
local Axis
local OppositePointPosition
local PointPosition
local ChosenRoom
local GAxis
local Possible
local MaxGenerations = 50
local Generated = 0
local AvailableRooms = {}
for _,room in pairs(Rooms:GetChildren()) do
table.insert(AvailableRooms, room)
end
while wait(15) do
if Generated >= MaxGenerations then
print("Exceded generations")
break
else
GAxis = math.random(1,4)
if GAxis == 1 then
Axis = "North"
if previousRoom:WaitForChild("CheckValues"):WaitForChild("North").Value ~= true then
local X = ((previousRoom:GetExtentsSize().X/2)+previousRoom:GetPrimaryPartCFrame().X)-1
local Y = previousRoom:GetPrimaryPartCFrame().Y
local Z = previousRoom:GetPrimaryPartCFrame().Z
PointPosition = Vector3.new(X,Y,Z)
Possible = true
else
Possible = false
end
elseif GAxis == 2 then
Axis = "South"
if previousRoom:WaitForChild("CheckValues"):WaitForChild("South").Value ~= true then
local X = (((previousRoom:GetExtentsSize().X/2)-previousRoom:GetPrimaryPartCFrame().X)*(-1))+1
local Y = previousRoom:GetPrimaryPartCFrame().Y
local Z = previousRoom:GetPrimaryPartCFrame().Z
PointPosition = Vector3.new(X,Y,Z)
Possible = true
else
Possible = false
end
elseif GAxis == 3 then
Axis = "East"
if previousRoom:WaitForChild("CheckValues"):WaitForChild("East").Value ~= true then
local X = previousRoom:GetPrimaryPartCFrame().X
local Y = previousRoom:GetPrimaryPartCFrame().Y
local Z = (((previousRoom:GetExtentsSize().Z/2)-previousRoom:GetPrimaryPartCFrame().Z)*(-1))+1
PointPosition = Vector3.new(X,Y,Z)
Possible = true
else
Possible = false
end
elseif GAxis == 4 then
Axis = "West"
if previousRoom:WaitForChild("CheckValues"):WaitForChild("West").Value ~= true then
local X = previousRoom:GetPrimaryPartCFrame().X
local Y = previousRoom:GetPrimaryPartCFrame().Y
local Z = ((previousRoom:GetExtentsSize().Z/2)+previousRoom:GetPrimaryPartCFrame().Z)-1
PointPosition = Vector3.new(X,Y,Z)
Possible = true
else
Possible = false
end
end
if Possible then
local GChosenRoom = math.random(1,#Rooms:GetChildren())
ChosenRoom = AvailableRooms[GChosenRoom]:Clone()
if Axis == "North" then
local X = (((ChosenRoom:GetExtentsSize().X/2)-ChosenRoom:GetPrimaryPartCFrame().X)*(-1))+1
local Y = ChosenRoom:GetPrimaryPartCFrame().Y
local Z = ChosenRoom:GetPrimaryPartCFrame().Z
OppositePointPosition = Vector3.new(X,Y,Z)
elseif Axis == "South" then
local X = ((ChosenRoom:GetExtentsSize().X/2)+ChosenRoom:GetPrimaryPartCFrame().X)-1
local Y = ChosenRoom:GetPrimaryPartCFrame().Y
local Z = ChosenRoom:GetPrimaryPartCFrame().Z
OppositePointPosition = Vector3.new(X,Y,Z)
elseif Axis == "East" then
local X = ChosenRoom:GetPrimaryPartCFrame().X
local Y = ChosenRoom:GetPrimaryPartCFrame().Y
local Z = ((ChosenRoom:GetExtentsSize().Z/2)+ChosenRoom:GetPrimaryPartCFrame().Z)-1
OppositePointPosition = Vector3.new(X,Y,Z)
elseif Axis == "West" then
local X = ChosenRoom:GetPrimaryPartCFrame().X
local Y = ChosenRoom:GetPrimaryPartCFrame().Y
local Z = (((ChosenRoom:GetExtentsSize().Z/2)-ChosenRoom:GetPrimaryPartCFrame().Z)*(-1))+1
OppositePointPosition = Vector3.new(X,Y,Z)
end
ChosenRoom.Parent = workspace
ChosenRoom.Name = "CRoom"
ChosenRoom:WaitForChild("PrimaryPart").Position = OppositePointPosition
ChosenRoom:SetPrimaryPartCFrame(CFrame.new(PointPosition))
ChosenRoom:WaitForChild("PrimaryPart").Position = ChosenRoom:WaitForChild("Reset").Position
previousRoom = ChosenRoom
Generated += 1
else
print("Overlapping", GAxis, Axis)
end
for _,room in pairs(workspace:GetChildren()) do
if room.Name == "CRoom" or room.Name == "StartRoom" then
for _,checkBlock in pairs(room:WaitForChild("CheckBlocks"):GetChildren()) do
for i,v in pairs(workspace:GetPartsInPart(checkBlock)) do
if v ~= nil then
for _,checkValue in pairs(room:WaitForChild("CheckValues"):GetChildren()) do
if checkValue.Name == checkBlock.Name then
checkValue.Value = true
end
end
end
end
end
end
end
end
end
Problem:
I also observed that overlapping happens only in the south and north, the first check works, on the second check, it brakes