Table Descendants Problem

i have this code:

for y,z in pairs(scanZoneTest) do
		print(z:GetDescendants()[num])
	for i, v in pairs(z:GetDescendants()) do

The issue is that if I do z:GetDescendants()[num] it gets a valid descendant of workspace, but if i do the for loop (for i, v in pairs(z:GetDescendants()) do), all v logs is Camera, not any other descendant. What is wrong?

1 Like

Can you post the full script? print(v) only prints the Camera?

1 Like

code:

local scanZoneTest = { game.Workspace }

for y,z in pairs(scanZoneTest) do
		print(z:GetDescendants()[num]) -- prints all descendants when indexed
	for i, v in pairs(z:GetDescendants()) do
              print(v) -- only prints Camera out of all descendants in workspace
end
  end
1 Like

Works for me, in starter player scripts and in server script service. I’m assuming you do have more than a Camera in the workspace, could you post your workspace?

1 Like

spaces

1 Like

Is there a reason you’re disjointing things, like scanZoneTest?

Would your use case not allow you to do:

for k, v in pairs(game.Workspace:GetDescendants()) do
    print(v)
end

workspace was only for testing, I am going to add more services to scanZoneTest

1 Like

I don’t really know what you are trying to do but! I will possibly think of one thing.

Try this:

for i,v in pairs(scanZoneTest:GetDescendants()) do 
        print(v)
end

if scanZoneTest is a Folder or Model or anything else that should work. Let me not if i got it right, or i’m stupid and i don’t know how to read :rofl:

scanZoneTest is a table lol

also doesnt work

1 Like
local scanZoneTest = { game.Workspace }

for y,z in pairs(scanZoneTest) do
	warn(z:GetDescendants()) -- warns the descendants table (verify your data)
	for i, v in pairs(z:GetDescendants()) do
		print(string.format("Found Descendant \"%s\" [Path: %s]", tostring(v), v:GetFullName()))
	end
end

Works just fine for me. Maybe show us what it’s outputting in a screenshot?

1 Like

Didn’t know this was a plugin; I’m not sure if that will change the behavior or not. Let me test and I’ll get back to you.

Nope, it didn’t change the behavior for me at all.
What else does your plugin do before this is printing? Because this is a really weird issue in my opinion.

1 Like

I was doing debugging and switched some of the variables and tables around and it started working. Not rlly sure what i did but hey, at least it works

1 Like