Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How can I count the frequency of values in a list?

So, this may be a terrible terrible setup because its my first time trying one. But I am trying to do map voting and when the player votes their userId gets added to a table with the map they voted. and to get the frequency I tried doing this

local function countFreq(tab)
	local freq = {};
	for _, v in ipairs(tab) do
		freq[v] = (freq[v] or 0) + 1;
	end
	return freq;
end

Always returns nil even if there is votes, and or duplicate votes.

8 comments

0

have you tried printing freq[v] after you changed it

0

also semicolons aren't needed in roblox lua

0

also what s the table "tab" supposed to contain?

0

Holy illiterate.

0

semicolons why

0

people who use semicolons > skrubs with spaghetti code ????

0

thats just an excess burden though

0

How, the semicolon is literally right next to shift it takes no extra work to press. Other languags I program in require it and I think Lua is more readable with it

1 answer

This discussion is preserved as it was. New answers, comments, and votes are closed.