Amount of table entries always returns 0

Sup, I try to save player Ids and their rank in a table that I cloned from a Template, but when trying to get the amount of PlayerIDs in a table it always returns 0

local FactionTemplate = {
	Name		="placeholder",
	Display 	="Display Name",
	Tag			="[000]",
	Desc		="A very cool faction",
	Banner		="rbxassetid://", --saves actual ID only
	Icon		="rbxassetid://",
	Owner		=nil,
	Members	= {
		--["1234567890"] = "Owner", Only how tis supposed to look like, actual scrit doesnt specify these
		--["000000001"] = "Officer",
	},
}

			local Table		=table.clone(FactionTemplate)
			Table.Owner			=Player.UserId
			Table.Members[Table.Owner] = "Owner"
			print(#Table.Members)

Could you try this and let me know what you got?

local memberCount = 0
for _.v in pairs(Table.Members) do
	memberCount = memberCount + 1
end

print(memberCount)

# operator only works with arrays (tables with numeric keys starting from 1).

1 Like

Looks like a dictionary, can’t grab the length of those with # :grimacing:

  1. Make a custom counter (easy)
local function dictionaryCount(tableSent)
    local counter = 0

    for _, _, in tableSent do
        counter += 1
    end

    return counter
end

dictionaryCount(Table.Members)

OR

  1. turn the members into an array [1, 2] and then put the info in a table inside of the array number, so like [1] = {Name = β€œ12313”} (meh, I think the custom counter is better)
1 Like

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