How do I iterate through multiple models/tables

I want to iterate through all of these droppers

The problem is it prints only 1 DropPart when I requested to iterate through all the droppers and it found only 1 DropPart (it has to find 7 DropParts)
image
image

I tried devforum it doesn’t correlate with my work.

I hope I’ve explained, swiftly
Sorry if the title is misleading/wrong I’m really bad at explaining things

local DropPart = Dropper.Dropper.DropPart
local PurchaseHandler = Dropper.PurchaseHandler
local Debris = game:GetService("Debris")
local TimeCounter = 2

local Droppers = game.Workspace.Droppers


local function SpawnCubic(Dropper)
	while true do
		wait(TimeCounter)
		local Cubic = game.ServerStorage.Cubic
		local ClonedCubic = Cubic:Clone()
		ClonedCubic.Name = "Cubic"
		ClonedCubic.Parent = game.Workspace
		ClonedCubic.Size = Vector3.new(1,1,1)
		ClonedCubic.Position = Dropper.DropPart.Position
		ClonedCubic.Position = ClonedCubic.Position - Vector3.new(0,1,0)
	end
end

PurchaseHandler.Touched:Connect(function()
	for _,part in pairs(Dropper:GetChildren()) do
		part.Transparency = 0; part.CanCollide = true
	end
end)

PurchaseHandler.TouchEnded:Connect(function()
	PurchaseHandler:Destroy()
	SpawnCubic(Dropper)
end)

local module = require(game.ServerScriptService.PriceTag)
module.myfunc()

local module = {}

local Dropper = workspace.Droppers.Dropper1
local DropPart = Dropper.Dropper.DropPart
local sc = game.ServerScriptService.Script
--local PurchaseHandler = Model.PurchaseHandler
local Debris = game:GetService("Debris")
local TimeCounter = 2

local Droppers = game.Workspace.Droppers
local Dropper1 = Droppers.Dropper1
local Dropper2 = Droppers.Dropper2
local Dropper3 = Droppers.Dropper3
local Dropper4 = Droppers.Dropper4
local Dropper5 = Droppers.Dropper5
local Dropper6 = Droppers.Dropper6
local Dropper7 = Droppers.Dropper7

local t = {Dropper1,Dropper2,Dropper3,Dropper4,Dropper5,Dropper6,Dropper7}

module.myfunc = function()
	table.unpack(t)
	for i,v in pairs(table.unpack(t):GetDescendants()) do
		if v.Name == "DropPart" then
			print(v)
		end
	end
end

return module

Why don’t you try looping through the ‘Droppers’ model, since you are finding the descendants of the model anyway?

Something along the lines of:

for i,v in pairs(Droppers:GetDescendants()) do
	if v.Name == "DropPart" then
		print(v)
	end
end

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