Help with :GetChildren() and for loops

I have a for loop like the one below. Instead of accessing the doors:getchildren with a name, I want to access it with the number it is in the array.

local doors = model.Doors
	
	for i=1,#doors:GetChildren() do
             doors[i] -- i want to access it not based on the name, but on the order of objects in the array
    end

the real script I am working on is below. I am trying to create and infinitely generated game. I am having trouble with the for loop in the create function.

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local floor = ReplicatedStorage.Floor
local start = workspace.Start

function Create(model)
	local doors = model.Doors
	
	for i=1,#doors:GetChildren() do
		
		local floorNum = math.random(1,#ReplicatedStorage.Floor:GetChildren())
		
		local newFloor = ReplicatedStorage.Floor:GetChildren()[floorNum]:Clone()
		newFloor.Parent = workspace.New
		
		local newDoors = newFloor.Doors:GetChildren()
		local randomNum = math.random(1,#newDoors)
		
		newFloor.PrimaryPart = newDoors[randomNum]
		newFloor:SetPrimaryPartCFrame(doors[i].CFrame)
		doors[i]:Destroy()
		
		if #newFloor.hitbox:GetTouchingParts() > 0 then
			newFloor:SetPrimaryPartCFrame(newDoors[randomNum].CFrame * CFrame.Angles(0,math.rad(180),0))
		end
		
		if #newFloor.hitbox:GetTouchingParts() > 0 then
			newFloor:Destroy()
		else
			newDoors[randomNum]:Destroy()
			newFloor.hitbox:Destroy()
		end
		
	end
	doors:Destroy()
end

Create(start)
local children = workspace.New:GetChildren()

for _, child in ipairs(children) do
	Create(child)
end

Can’t you just for loop through the children and get the count of the child?

for count, child in pairs(doors:GetChildren()) do
    print(count, child.Name)
end

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.