Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do I add the names of a model's children to an existing table?

I have tried this, but I seem to be having no luck.

local chil = game.ReplicatedStorage.Maps:GetChildren()

for i,v in pairs(chil) do
	local num = 1
	table.insert(_G.Dialog.Options,num,chil.Name)
	num = num + 1
end

Any help would be appreciated

3 comments

0

pls use code block and not quotes

0

chil is the table (array) and chil.Name is trying to access the value held in the key called Name. In the loop v ins the child so _G.Dialog.Options[#_G.Dialog.Options+1] = v.Name is what you need

0

I would also avoid the use of _G

1 answer

✓ Accepted answer

It looks like you're trying to combine the two methods of iterating a table: the key-value pair method, and the list/index method. If you want to use pairs, that's fine, but you may as well make use of the variables that they call for:

local maps = {} -- New table
local chil = game.ReplicatedStorage.Maps:GetChildren()
for i,v in pairs(chil) do
    table.insert(maps,v.Name)
end

The use of the global table is not recommended. If you need to share a table between scripts, consider using a module script instead and just return the table at the end of the script.

1 comment

0

could alsp use get desents

This discussion is preserved as it was. New answers, comments, and votes are closed.