I'm currently trying to learn how to use modules. I think I could figure it out if I knew how to do the simple first.
I have a regular script in ServerScriptService
and a module script in Workspace named test
. There's nothing else in the workspace named that, I checked.
Here's the Server Sided Script,
local module = game.Workspace:WaitForChild("Test") local output = require(module) output(5)
Here's the module,
local function output(num) print(num * num) end return output()
Line two of the first script give me an error,
02:31:13.293 - Requested module experienced an error while loading 02:31:13.293 - Script 'ServerScriptService.ModuleReturnTest', Line 2
I'm not sure what that means though :/
Any help is appreciated
Thank you.
You are returning the return value of a call to your output
function instead of returning your output
function itself. Since your function doesn't actually return anything, it resolves to nil.
In your other script, you capture this nil value and assign it to "output". The whole purpose of require()
ing a module is to capture and keep the return value, hence the error.