Table only inserting one value even though multiple should be added

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]

print(music[AFireflysPhantasm])

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
end
for i,v in pairs(music) do
	print(i,v)
end

Output:
image
Explorer:
image

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).

2 Likes

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
print(music)

Screen Shot 2020-07-30 at 9.13.50 PM

ok now try this

table.foreach(music, function(musicName,musicId)
print(musicName,musicId)
end)
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

yeah its might be a bug, if you did that it should only print

table:randomnumberhere 
1 Like

Will do, thanks!

It seemed to work before, not sure what’s going on here though.

Edit: it’s already been reported.