Table only inserting one value even though multiple should be added


I have a table as a dictionary and I am trying to insert multiple music IDs into it for later use, however only one ID is being inserted and I have no idea why.

local music = {}

for i,v in ipairs(workspace.MapsArchive:GetChildren()) do

    local musicID = v:WaitForChild("Settings"):WaitForChild("Music")

    music[v.Name] = musicID.Value



All that’s being outputted is this:

   ["TremaineTranquility"] = 1836640373

Here’s the heritage of the maps, they are the direct child of workspace:

Screen Shot 2020-07-30 at 9.00.49 PM

1 Like

Well for starters your not even using table.insert, how about you try to insert it using table.insert

1 Like

Could I see the v childrens ??

I think OP using dictionary, which cant use table.insert

You can still use table.insert on a dictionary

I don’t think table.insert allows non-numerical indexes.

Here’s the children. It’s the same for each map.

Screen Shot 2020-07-30 at 9.08.45 PM

How about you just insert the names into the table and then when you need the name just find the one that matches the id your looking for

1 Like

Try doing the music[AFireflysPhantasm] or music[Any map name]


1 Like

The issue is that table.insert always inserts a numerical value. It’s easier to just do local musicid = music.MapName than assign numbers to each maps, especially if I want to add more maps in the future.

What do you mean always inserts a numerical number? You can insert strings and booleans

ipairs will stop at a nil value, how a nil value is being discovered I’m not sure so this may not be the issue, but nevertheless perhaps change this from an ipairs to a pairs loop for testing purposes?

I’ve attempted it myself replicating your system and it works fine for me which leads me to believe it is a loading latency issue:

local music = {}
for _,model in ipairs(game.ServerStorage.Folder:GetChildren()) do
	musicId = model:WaitForChild("Music")
	music[model.Name] = musicId.Value
for i,v in pairs(music) do


If this is a matter of loading, perhaps you could add a wait() prior to the loop so that everything has the time to load in.

@loveicicIe there is nothing wrong with him using a dictionary as opposed to an array or a table in this situation, there’s no need to advise him against using something that isn’t harming his script in anyway (and the transition wouldn’t benefit his script either).


I never told him to use an array though??
But anyway @Imp_erator thanks, also @danthemanroblox192 I visited the link thanks

1 Like

It seems to only output one value for some reason, here’s what I ran, I used single-digit values as placeholders:

local music = {}
music["AFireflysPhantasm"] = 5
music["CliffsideCemetery"] = 1

Screen Shot 2020-07-30 at 9.13.50 PM

ok now try this

table.foreach(music, function(musicName,musicId)
1 Like

I tried pairs to no avail. Also, keep in mind that the music isn’t the direct child of the map, it’s a child of the Settings folder.

That worked, it outputted each value. Not sure how to use foreach though, I can read up on it.

1 Like

ok so your table work, but i think @lmp_erator have a good point using ipairs when dealing with table, so if you want to play all music do the table.foreach, and if you want to play a specific one, do music[Maps Name]

1 Like

Yeah, I think it could be a bug as I’m using the beta output window. Thanks for the solution!

I’d report this as a bug for the output window, (the fact that it only displays the first iteration of a dictionary in the output).

1 Like