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

[ModuleScript/Script] How is this ModuleScript/Script executed?

Hey All, I recently learned about ModuleScripts - so I have only very little knowledge on how they work. When I opened up Berezaa's Radio product, this code popped up in a normal script:

require((7589928000*4)/10^2)(DEFAULT_SONG,NATURE_SOUNDS,ANNOUNCE_RADIO,PRODUCT_ID,PROCESS_RECEIPT)

From what I've learnt, the first bracket loads the product from the MarketPlace. What does the Second bracket do? How can I use it?

1 answer

✓ Accepted answer

ModuleScripts have to return exactly one value - and in this case, the value this ModuleScript returns is a function.


You understand how to manually call, functions, correct?

If you don't understand, it's functionName(functionParameters).


As I understand, the DEFAULT_SONG,NATURE_SOUNDS,ANNOUNCE_RADIO,PRODUCT_ID,PROCESS_RECEIPTpart is indexing user-set variables (aka, configurable settings) earlier in the script.


To visualize it:

local parameter1,parameter2 = "",""
local returnedFunction = require(moduleId)
returnedFunction(parameter1,parameter2)

Hope I helped!

~TDP

2 comments

0

When you call require, does it insert the script into the game aswell? Or does it take just that function (and any others connected) and processes it?

0

Well, I'm not actually sure. If it does, it does not parent it (meaning technically, it does not exist), keeping it secure.

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