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

What does require(ID)(soemthing) mean in a module?

Asked by 5 years ago

i saw this script and it did

require(someID)(data)

i have been wondering how i can do this with a module i have tried

require(moduleScript)(data)
--in a different script
return function(data)
end

but it didnt work, please help

1 answer

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

The "ID" part of it comes from a published module script. They upload the module script to Roblox and use the number in the module's link like an audio to run it in their game.

I'm unfamiliar with the "data" part, but I think it runs a function inside the module script with "data" as an argument.

Here's an example of how it works:

Script:

local Module = require(script.Parent.TestModule)("Test") -- Requires module and and puts an extra parenthesis to run the function. "Test" is an argument.

Module Script:

local function TestFunction(data) -- Note that we put "Test" as an argument, so data = "Test"
    print(data) -- Prints "data"
end

return TestFunction -- The module returns the function, so requiring the module actually gives the function itself.

Hope this helped! If you have any questions, just comment!

Ad

Answer this question