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

When i Use Module Scripts They Wont Work?

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

✓ Accepted answer

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")

2 comments

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?

0

i moved them to ServerScriptService and did what you said it worked i shouldnt of had them in Server Storage

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

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