Getting the parts within all the models within a folder

I have a folder with different layers of a platform. Each layer is a model named 1-19 and each layer is consisted of parts or “Tiles”. I’m trying to write a function to perform operations at the same time for each tile on a serversided script. The tiles will be individually all be doing something at the same time and I will eventually drop off the layers at specific times. However, I’m stuck on the first while loop.
Layer(folder) — > Model1-19 — > x amount of Tiles

I tried using for num, child in pairs(model.GetDescendent()) do originally, however that didn’t work and I have no clue what I’m able to do from here.

local model = script.Parent
local Layer1 = model["1"]

local GAME_START = game.Workspace.GameStart
local GAME_ACTIVE = true
local timer = 15

while GAME_ACTIVE == true do
	for index = 1, #model do   --- trying random stuff here
		for num, child in pairs(index:GetChildren()) do 
			FallEvent = math.random(0,1)
			RiseEvent = math.random(0,4)
			BlockWait = math.random(0,10)
			BlockWait1 = math.random(2,6)
			if FallEvent == 0 then
				wait(BlockWait)
				child.BrickColor = BrickColor.new("Crimson")
				wait(2)
				child.Transparency = 1
				child.CanCollide = false
				wait(2)
				child.Transparency = 0
				child.CanCollide = true
				child.BrickColor = BrickColor.new("Medium stone grey")
			end
		end
	end
end

while GAME_ACTIVE == true do
	while timer > 0 do
		wait(1)
		timer = timer - 1
		print(timer)
		if timer == 0 then
			for num, child in pairs(Layer1:GetChildren()) do
				child.Transparency = 1
				child.CanCollide = false

			end
		end
	end
end
2 Likes

I’m not entirely sure I understand what you’re going for but I think I see your error. In the second for loop you’re doing for num, child in pairs(index:GetChildren()) do however index is just an integer so :GetChildren() would not return anything as it’s just a number.

To fix this I’d do something like this:
You could change the first for loop to this format for _,index in pairs(model:GetChildren()) do. and that way index is the actual objects that are inside the models.

To clarify further, index is an integer in your original code because your first for loop is simply setting index to 1, then 2, 3, etc… until it reaches #model (which is possibly not even a number in the first place)

2 Likes

Gotcha that makes sense, thanks for the explanation!
Now I just got to figure out how to use the mechanics(FallEvent) for each tile simultaneously and I’m golden :). I think I have an idea for that.
Appreciate the help!