Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
-1

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

Asked by 5 years ago
Edited 5 years ago

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

0
pls use code block and not quotes User#5423 17 — 5y
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 User#5423 17 — 5y
0
I would also avoid the use of _G User#5423 17 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

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.

0
could alsp use get desents danglt 185 — 5y
Ad

Answer this question