Room Generation Script Not Working? (Output Error Issues)

Trying to make a room generation script but getting error in the Output:

" ServerScriptService.Server.Room:17: attempt to index nil with ‘Name’ "

Will someone help me figure out what’s wrong? I’ve been trying to fix the issue for a few hours ._.

What solutions have you tried so far?
I’m on a discord server to help w/ scripting but the recommendations I was given didn’t fix the issue.

Screenshots of Explorer:


Screen Shot 2022-11-25 at 9.03.58 PM

Server Script

local room = require(script.Room)

local PrevRoom = workspace.StartRoom

for i=1, 10 do
	PrevRoom = room.Generate(PrevRoom) -- this is the line of code w/ the error
end

Room Module Script

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)]
		--[1]Nxt room must be dif than prev room
		--[2]if corner then next turn other way
		--[3]if prev room = stairs, then next cannot
		
		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) 	
			or (direction and direction == room.lastTurnDirection)
			or (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()
	local newRoom = randomRoom:Clone()

	newRoom.PrimaryPart = newRoom.Entrance
	newRoom:PivotTo (PrevRoom.Exit.CFrame)
	newRoom.Entrance.Transparency = 1
	newRoom.Exit.Transparency = 1

	newRoom.Parent = workspace.GeneratedRooms

	return newRoom
	end
end
	return room

RoomInfo Module Script

local roomInfo = {
	["StartRoom"]= {

	},
	["UpStairs"]= {
		["Stairs"] = true
	},
	["DownStairs"]= {
		["Stairs"] = true
	},
	["Hall1"]= {

	},
	["Hall2"]= {

	},
	["Classroom1"]= {

	},
	["Classroom2"]= {

	},
	["CornerHall1"]= {
		["Direction"] = "Right"
	},
	["CornerHall2"]= {
		["Direction"] = "Left"
	},
	["CornerClass"]= {
		["Direction"] = "Right"
	},
}

return roomInfo

I really appreciate it! :slight_smile:

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)]
		--[1]Nxt room must be dif than prev room
		--[2]if corner then next turn other way
		--[3]if prev room = stairs, then next cannot
		
		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) 	
			or (direction and direction == room.lastTurnDirection)
			or (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.Entrance
	newRoom:PivotTo (PrevRoom.Exit.CFrame)
	newRoom.Entrance.Transparency = 1
	newRoom.Exit.Transparency = 1

	newRoom.Parent = workspace.GeneratedRooms

	return newRoom
	end

	return room

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.