I am trying to get rooms to generate in such a way that no room can be repeated twice in a row, as well as to keep multiple left/right turns from occurring too quickly. This seems like it should work, yet I get this error every time I try to run it.
Below is the serverscript and two modulescripts I am using
Server
local prevRoom = workspace.StartRoom
for i=1, 10 do
prevRoom = room.Generate(prevRoom)
end```
Module (the one that is causing problems)
```local room = {}
room.info = require(script.RoomInfo)
room.LastTurnDirection = nil
room.random = Random.new()
function room.GetRandom(prevRoom)
local possibleRooms = workspace.Rooms:GetChildren()
local RandomRoom = possibleRooms[room.random:NextInteger(1, #possibleRooms)]
local direction = room.info[RandomRoom.Name]["Direction"]
local hasStairs = room.info[RandomRoom.Name]["Stairs"]
local prevHadStairs = room.info[prevRoom.Name]["stairs"]
if prevRoom.Name == RandomRoom.Name then
return room.GetRandom(prevRoom)
elseif direction and direction == RandomRoom.LastTurnDirection then
return room.GetRandom(prevRoom)
elseif hasStairs and prevHadStairs then
return room.GetRandom(prevRoom)
else
if direction then
room.LastTurnDirection = direction
end
return RandomRoom
end
end
function room.Generate(PrevRoom)
local RandomRoom = room.GetRandom(PrevRoom)
local newRoom = RandomRoom:Clone()
newRoom.PrimaryPart = newRoom.Enter
newRoom:PivotTo(PrevRoom.Exit.CFrame)
newRoom.Enter.Transparency = 1
newRoom.Exit.Transparency = 1
newRoom.Parent = workspace.GeneratedRooms
return newRoom
end
return room```
Module
```local roomInfo = {
["StartRoom"] = {
},
["SmallRoom"] = {
},
["MediumRoom"] = {
},
["FirePlaceRoom1"] = {
["Direction"] = "Left"
}
}
return roomInfo```