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

Are you able to send tables when requiring a ModuleScript?

Asked by 6 years ago

Am I able to send tables, when I require a module in my inventory. I keep getting an error saying, "ServerScriptService.Script:7: attempt to call a number value"

local settings = {
    groupId = 0;
    minStaffRank = 0;
    minAdminRank = 0
}

require(1913364255)(settings)
0
Yes, you can. It may be another script in your module or something. popeeyy 493 — 6y

1 answer

Log in to vote
1
Answered by
Avigant 2374 Moderation Voter Community Moderator
6 years ago
Edited 6 years ago

If you meant returning a table, yes, you can simply return a table from your ModuleScript. Since table values are of reference type, and module return values are cached, every time you require the module, a reference to the same table will be returned.

If you want to send a table to a ModuleScript via a function it returns, I recommend returning a function that takes a table as an argument, and operates on that, but that's not particularly useful, and limits how other scripts and modules can interact with your module. Instead, I recommend passing data the module needs as arguments to functions, and returning a dictionary of functions from your module.

In your case, you are attempting to call a function that the module returns, but it returns a number, and this isn't what you want. Additionally, I recommend against requiring modules by ID, it's much better to insert them into Studio and require them by their instance.

0
Have I figured out what I did wrong. Thank you though for the help! papasherms 168 — 6y
Ad

Answer this question