Loop through folder and add contents to table not working

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve?
    I want to loop through a folder and add its contents to a table

  2. What is the issue?
    The values are not getting added to the table, but the printing works fine. (Comes out as nil)

wlMembers = {}

while true do
	wait(1)
	for _,v in pairs(wlF:GetChildren()) do
		if v and v:IsA("StringValue") then
			table.insert(wlMembers, v.Name)
		end
	end
	for index, value in pairs(wlMembers) do
		print(index, value)
	end
end
  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I have tried fiddling around with everything I know how to do, all help is appreciated <3

Shouldn’t you make wlMembers a local variable? Like…

local wlMembers = {}
2 Likes

What do you mean the printing works fine? Do both values come out nil?

GetChildren returns an array, not a dictionary. So use ipairs instead.

1 Like

Are you okay man? That’s not how it works. Lua itself doesn’t even have dictionaries

ummmmm. That is what the roblox dev hub articles call them and the api references. It is just all the data in the tables

local dictionary = {ThisIsAKey = "ThisIsAValue"}
local array = {"Value1", "Value2"}
for Key, Value in pairs(dictionary) do
    print(Key, Value)
--> ThisIsAKey ThisIsAValue
end
for Index, value in ipairs(array) do
    print(Index, Value)
--> 1 Value1
--> 2 Value2
end

if you try using ipairs on a dictionary or vise versa, it won’t go through it, iirc.

Sorry for late responses

local wlMembers = {}

while true do
	wait(1)
	for _,v in ipairs(wlF:GetChildren()) do
		if v and v:IsA("StringValue") then
			table.insert(wlMembers, v.Name)
		end
	end
	for index, value in pairs(wlMembers) do
		print(index, value)
	end
end

I have tried your guys’ suggestions but the output is still empty, even when I added a few string values.

If I put something in the array in the script, it’ll print out 1, “value” just fine

Yes, but lua itself doesn’t contain dictionaries in the code itself, you are able to “make” dictionaries but in the end they get converted back to [1] = {“Yeet” = “Yeet”} after it compiles.

Yes but I’m saying itself that Lua doesn’t have any dictionaries

Add some prints to see what data is being added aka

local wlMembers = {}

while true do
	wait(1)
	for _,v in ipairs(wlF:GetChildren()) do
		if v and v:IsA("StringValue") then
            print(v.Name, v.Value)
			table.insert(wlMembers, v.Name)
		end
	end
	for index, value in pairs(wlMembers) do
		print(index, value)
	end
end