Dictionary having 0 values

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!

I wanna be able to use for loops with the dictionaries.

  1. What is the issue? Include screenshots / videos if possible!

I used a for loop but it just didnt run.

  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?

I printed the length of the table with # operator but it just said 0.

local Test = {
	Test1 = 1;
	Test2 = 2;
	Test3 = 3;
}

print(#Test)

Screenshot 2021-06-29 111922

If you need to loop through a dictionary, use this:

for i, v in pairs(dictionaryHere) do

end
local Amount = 0
local Test = {...}
for i,v in pairs(Test) do
Amount += 1
end

print(Amount) 

To get the length of a dictionary, use this function:

local function getDictionaryLength(dict)
	local length = 0
	for k, _ in pairs(dict) do
		length += 1
	end
	return length
end

It works with any dictionary entry type, such as:

local dictionary = {
	['hi'] = 8,
	'lol',
	'bye',
	['no'] = 0
}

It worked fine for me… any errors?

works now but the for loop only loops through one value, not three

What dictionary are you inputting?

well it works in the script i tested but not if i get a table from a modulescript

Can you print the table and see what you get? It is probably because the table is nil.

Oh i fixed it. Basically I used a RemoteEvent and fired an event from the localscript with the type of modulescript. I forgot that modulescripts are different for the server and client.