Room generation help?

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.
image

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```

I’m aware it isn’t formatted correctly i’m working on that

You are attempting to index nil with “Direction”, I assume this is happening on line

this means that room.info[RandomRoom.Name] is nil, you can verify this by putting a print(room.info[RandomRoom.Name]) before that line. If this prints nil, then make sure require(script.RoomInfo) has the key RandomRoom.Name.

You are just messing up with modules.


Note that the first call to require on a ModuleScript will not yield (halt) unless the ModuleScript yields (e.g. calls wait). The current thread that called require will yield until a ModuleScript returns a value. A run time error is generated if this doesn’t happen. If a ModuleScript is attempting to require another ModuleScript that in turn tries to require it, the thread will hang and never halt (cyclic require calls do not generate errors). Be mindful of your module dependencies in large projects!

  • You can read this one here.

I suggest you creating instances on ServerStorage and save your variables there instead of using another module script. Perhaps just define a table right up the first module. It isn’t necessary to have one calling another.