Is it possible to get numbers of multiple instances

hey, trying to get number of instances

print((#workspace:GetChildren()) and (#workspace.Npcs:GetChildren()))

real question here is it possible to check 2 instances in one instead of making a serepate function for it?
example:
8 children, 10 npcs
aka something like this
am

you can do this

local tableToCheck = workspace:GetChildren() and workspace.Npcs:GetChildren()
for i,v in pairs(tableToCheck) do
local t = {}
table.insert(t, table.unpack(workspace:GetChildren()))
table.insert(t, table.unpack(workspace.Npcs:GetChildren()))
for i,v in pairs(t) do

Tried @neweve2323’s solution without success:

local a = {"a"} local b = {"b"} local c = a and b for i,v in pairs(c) do print(i,v) end
-->
1 b

am
how do i fix this error

See here a function that concatinates 2 tables:

local a: Folder = workspace.a
local b: Folder = workspace.b

local function tableConcat(t0,t1)
	for i = 1, #t1 do
		t0[#t0 + 1] = t1[i]
	end
	return t0
end

local t = tableConcat(a:GetChildren(), b:GetChildren())
for i,v in pairs(t) do
	print(i,v)
end
--output-->
 1 aaaa
 2 sjdlqsjd
 3 bbbb
 4 omklmk

image

Probably the quickest way of doing this, although it only works to concat 1 table to another. If you need to do this with multiple tables, it would require more looping.

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