Hey, I have an issue with my code, here is the error: ServerScriptService.Server.Room:10: attempt to index nil with 'Lights' - Serveur - Room:10
Here is my Server script:
local room = require(script.Room)
local door = require(script.Room.Door)
local baconspirit = require(script.BaconSpirit)
local prevRoom = workspace.Entrance
local playerEnter = script.Room.PlayerEnter
local firstDoor = door.New(prevRoom, 1)
local generatedRooms = {prevRoom}
for i=2, 61 do
prevRoom = room.Generate(prevRoom, i)
generatedRooms[i] = prevRoom
end
playerEnter.Event:Connect(function(number)
if number % math.random(2,10) == 0 then
room.Blackout(generatedRooms[number])
room.Blackout(generatedRooms[number+1])
task.wait(2)
baconspirit.New(number, generatedRooms)
end
end)
Here is my Room script:
local door = require(script.Door)
local furniture = require(script.Furniture)
local room = {}
room.info = require(script.RoomInfo)
room.lastTurnDirection = nil
room.random = Random.new()
function room.Blackout(roomModel)
local lamps = roomModel.Lights:GetChildren()
for i, lamp in ipairs(lamps) do
for i, obj in ipairs(lamp:GetChildren()) do
if obj.Name == "Lights" then
obj:Destroy()
end
end
end
end
Thanks if you help me!
(PS: The code from the YouTuber “GnomeCode”, so you can check the “Making Rush Monster AI” video to help me.)
Is the model you send to the function only the model name, or is it the path to the model (workspace.Model for example)? If it’s only the name you’re sending, then that should be the problem. Else it might be a spelling error either in the script or inside of the roomModel, such as one having capital L and the other lower L.
If it’s a model or file with children, try this:
print(generatedRooms:GetChildren())
If it’s a table made in a script, try this:
print(generatedRooms)
If the printed result is an empty list, there are no values in generatedRooms, thus creating an error.
If this is the case, can you post the part of code that sends generatedRooms?