Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Module Script #Table returns 0?

Asked by 4 years ago
Edited 4 years ago

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.

0
Pretty sure you can't do #dict, you have to loop over the dictionary and count the keys fpnky 0 — 4y
0
Ah, thank you then. zboi082007 270 — 4y

1 answer

Log in to vote
1
Answered by
xXLuka_XD 103
4 years ago

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.

0
I already got an answer from fpnky, but thanks anyway. zboi082007 270 — 4y
Ad

Answer this question