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

Module Script #Table returns 0?

Module Script:

	local News = {
	["Broadcast1"] = {
		-- dictionary information here
		},
	["Broadcast2"] = {
		-- dictionary information here
		}
}

return News

Local Script

local newsModule = require(script.Parent.Parent.Parent.Parent.NewsModule)

local broadcasts = #newsModule
print(broadcasts)

For some reason, the table always returns as 0, even though there are 2 values in the table, help.

2 comments

0

Pretty sure you can't do #dict, you have to loop over the dictionary and count the keys

0

Ah, thank you then.

1 answer

✓ Accepted answer

Module scripts start with the identifier that acts like a table and returns it. Module scripts that way can be used anywhere, so for example you can use it's variables and functions everywhere.

I think that your issue here is that you didn't do it like this.

--module script

local News = {}

News.Broadcasts = {
    ["Broadcast1"] = {
        -- dictionary information here
        },
    ["Broadcast2"] = {
        -- dictionary information here
        }
}

return News

--script 

local newsModule = require(script.Parent.Parent.Parent.Parent.NewsModule)

local broadcasts = #newsModule.Broadcasts
print(broadcasts)

Tell me if it doesn't work.

1 comment

0

I already got an answer from fpnky, but thanks anyway.

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