Get number of things in a table

I’ve been progressively Improving my scripting skills yoo fast that i forgot how to get number of things in a table.

I dont mean this:

print(#{1,2,3,4}) --4

I want to number of keys in key-value pair table.
Example:

local Table = {
["Key"] = 2,
["instance"] = instance.new("part"), 
["Table"] = {1, 2,3,4,5}
}

--Normal behaviour
print(#Table) --0

--Wanted Behaviour
print(#Table) --3
1 Like
local Table = {
	["Key"] = 2,
	["instance"] = Instance.new("Part"), 
	["Table"] = {1,2,3,4,5}
}

local GetKeysInTable = function(Table)
	local Count = 0 
	for i,v in pairs(Table) do 
		Count+=1
	end
	return Count
end

print(GetKeysInTable(Table))
3 Likes

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