I’m creating a room-generating script, and i added specific rooms, like room 0 in doors, but the starting room isn’t considered being in ReplicatedStorage, but it is. Printing game.ReplicatedStorage:GetChildren()
returns {}
.
local config = {
["MAX_ROOMS_TO_KEEP"] = 0,
["SPECIFIC_ROOMS"] = {
[0] = game.ReplicatedStorage.starting,
},
}
local room = 0
local function loadNewLevel()
local function newLevel()
local exc = config["SPECIFIC_ROOMS"][room]
local level
if exc then
level = exc
else
level = game.ReplicatedStorage:GetChildren()[math.random(1,#game.ReplicatedStorage:GetChildren())]:Clone()
end
print(string.format("Current room: %d, Room: %s, special room: %s", room, tostring(level), tostring(exc)))
level.Name = tostring(room)
room += 1
level.Parent = workspace
if false then
level:WaitForChild("END").Transparency = 1
level:WaitForChild("START").Transparency = 1
end
return level
end
local previous = workspace:FindFirstChild(tostring(room-1))
if previous then
local level = newLevel()
level:PivotTo(previous:WaitForChild("END").CFrame)
else
local level = newLevel()
end
if config["MAX_ROOMS_TO_KEEP"] > 0 then
local to_delete = workspace:FindFirstChild(tostring(room-config["MAX_ROOMS_TO_KEEP"]))
if to_delete then
to_delete:Destroy()
end
end
wait()
end