Collection service and Dictionaries

hey, all im trying to achieve is a dictionary that has the entries of the material of the brick, and the corresponding color. but it is giving me strange outputs! I have added a few other prints to just check the values are correct - but they are and still, the table is giving me weird output!

heres the final variation of code i thought should work

local collection = game:GetService("CollectionService")
local tagged = collection:GetTagged("cool")
local list = {}


for _, tagged in pairs(tagged) do
	local material = tagged.Material
	local color = tagged.BrickColor
	print(material,color)
	list[material] = color
	
end
print(list)

and here the parts tagged:
image
apolgies for bad writing :sweat_smile:

here is the output:
image
whats happening???

ok, this seemed to work, but why does it work but not the first version?

local collection = game:GetService("CollectionService")
local tagged = collection:GetTagged("cool")
local list = {}
local x = {}
local y = {}

for _, tagged in pairs(tagged) do
		table.insert(x,tostring(tagged.BrickColor))
	table.insert(y,tagged.Material)
end

for dummy = 1,#x , 1 do
	list[x[dummy]] = y[dummy]
end
print(list)

I’ve never used CollectionService, but [token(gibrish)] is probably just unique identifier/index in list.

If you just want the material, you can do print(list[material])

While writing this I noticed that you are putting entry list[material] to color, instead of material variable.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.