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

works with module script, when module script is required it doesn't work?

Asked by 7 years ago
Edited 7 years ago

**essentially, im creating a private module. i place the main module in the game, it unpacks itself with the previously entered bricks etc, and everything works fine.

when you require a modulescript, it basically just inserts it and it's children into the script and runs them. (so im told)

however, when i require it, (yes the modulescript is named MainModule) it doesnt work. not in test mode or game mode and filtering enabled is not on.**

1 answer

Log in to vote
1
Answered by
Jellyfosh 125
7 years ago

ModuleScripts are generally used to call functions that you would use more than a few times and don't feel like writing out a lot. Basically you can put a function inside a module script and then call that same function from any script in the game that has required that ModuleScript. This means that you could also potentially store values in a ModuleScript if you have a function inside that returns said data to whatever script is calling for it. If that is what you are trying to do you can use something like this in the module script:

local funTable = {
    "A string", 12345, "Another string"
}

local module = {
    getFunTable = function()
        return funTable
    end
    }
return module

You would put this in your ModuleScript inside of ServerStorage. Now you can receive "funTable" from any Script/LocalScript by putting the following lines inside:

local moduleScript = require(game.ServerStorage.NAMEOFYOURMODULESCRIPT)
local returnedFunTable = moduleScript.getFunTable() --Calls getFunTable function+returns table
print(returnedFunTable[1]) 

This will print the first item in "funTable", which is "A string".

I hope this helps you in some way, your question was a little difficult to understand.

Ad

Answer this question