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](http://devforum-uploads.s3.dualstack.us-east-2.amazonaws.com/uploads/original/4X/a/4/4/a44833e5c508f3d86dfda00c4045c14ab01b7bd4.png)
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!