I am trying to make a script that gets a random "Chunk" which is a group/model in a folder in server storage, The problem is that when it tries to pick a random "Chunk" it has this error code: Workspace.ObbyGenerator:9: attempt to index a nil value
Here is the script (It is a regular script in game.Workspace):
local ChunkSize = 144
local ChunkCounter = 0
local Chunks = {game.ServerStorage.Chunks:GetChildren()}
math.randomseed(123)
function CreateNewChunk()
local ChunkCoordinate = ChunkSize * ChunkCounter
local ChunkPicked = game.ServerStorage:FindFirstChild(Chunks[math.random(1, #Chunks)]):Clone()
ChunkPicked.Parent = game.Workspace.Obby
ChunkPicked:MoveTo(Vector3.new(ChunkCoordinate + 144, 0.5, 0))
ChunkCounter = ChunkCounter + 1
end
local Obby = Instance.new("Model", game.Workspace)
Obby.Name = "Obby"
local firsthundredchunks = 100
repeat
firsthundredchunks = firsthundredchunks - 1
ChunkCounter = ChunkCounter + 1
wait()
until firsthundredchunks <= 0
while wait(3) do
CreateNewChunk()
ChunkCounter = ChunkCounter + 1
end

2 comments
game.ServerStorage.Chunks:GetChildren() returns a table, not a tuple
which means the Chunks table has one index and it is a table, not an object