Error With Random Room Generator

Hello! I was recently following a tutorial for random room generator code and I’m having trouble with this:


and the line I have my cursor on is getting this error:

I have no idea where to start in fixing this. Any ideas?

this?

if (prevRoom and prevRoom.Name == randomRoom.Name) or (direction and direction === room.lastTurnDirection) then

That is where the error is, yes

Try to see if the possible room exists first. Im not sure if this is the same as the code you wrote, but instead of room.random, try Random.new() instead

I already did up here, right?

The problem is that either prevRoom or randomRoom are nil, we know randomRoom isnt nil because you already index randomRoom.Name above, so prevRoom must be nil.

You can prevent the error by changing it to:

if (prevRoom and prevRoom.Name == randomRoom.Name) 

In case randomRoom is nil:

if ((prevRoom and randomRoom) and prevRoom.Name == randomRoom.Name)
1 Like

Is everything being done on a serverscript? I feel like the code should be working, but just in case check if the previous room and random room exists

What’s PrevRoom? I believe PrevRoom is causing the error. I see where you define randomRoom but I do not see PrevRoom being defined anywhere, causing it to return an error when attempting to retrieve a nil’s Name property

Edit: I do see the PrevRoom but are you passing anything to the function for the parameter PrevRoom?