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

When i Use Module Scripts They Wont Work?

Asked by 2 years ago
Edited 2 years ago

I have tried over and over to make what's in my module script work I tested it in a normal script and it works so I removed it and just tried to print no errors nothing can anyone tell me why

MODULE SCRIPT

local module = {
    myFunc = function()
        print("function processed")
    end
}


return module

Call Module

local functionTest = require(game.ServerStorage.ModuleScript)

print("done right")

I know its simple but it just won't work please help

2 answers

Log in to vote
3
Answered by
appxritixn 2235 Moderation Voter Community Moderator
2 years ago
Edited 2 years ago

The reason myFunc is not called is well... because you never actually call it.

The way you have your module setup, a function is defined within a table and required into a variable called functionTest.

functionTest is a table, not a function.

To call the function when the module is required, you could leave your "Call Module" script the same, and change the Module Script to look like this:

Option 1

local module = {
    myFunc = function()
        print("function processed")
    end
}

module.myFunc() -- this calls the function

return module

To continue with the module script as it is, you would call the function like this:

Option 2

local functionTest = require(game.ServerStorage.ModuleScript)

functionTest.myFunc() -- this calls the function "myFunc" from the module

print("done right")
0
i changed the Module Script to what you said still nothing in output so i reverted and changed the normal script that calls the module script and i got nothing so i combined them both and still got nothing? TheMiniMagic_YT 27 — 2y
0
i moved them to ServerScriptService and did what you said it worked i shouldnt of had them in Server Storage TheMiniMagic_YT 27 — 2y
Ad
Log in to vote
0
Answered by 2 years ago

i fount the answer im dumb i have them in serverstorage and it didnt work so i moved it to serverscriptservice and now its working

Answer this question