How would I add more information onto require()?

I’ve just learnt how to use require and now I need to know how would I attach more information onto require().

Heres my loader

local gamepass = 0000000 -- GamepassID

local donateuiperks = true -- Support DonateUI with allowing users to have donator perks from DonateUI <3

require(workspace.MainModule):Fire(game.workspace)

How would I add those two variables’ value to the module?

2 Likes

What do you want it to do? I dont understand why you would do that also isnt that require useless because you arent taking the table it gives you so isnt it useless?

I need the gamepassid and donateperks value for the module to process, how would I get that information from the loader to the module?

1 Like

The functions is the module

Script:
local functions = require(script.functions)
functions.function(put the data here)

Module:
local m = {}
function m.function(arg1,arg2) --Call it how you want
–Here is your code to process it
end
return m

I hope i understood what you need

Module scripts arent for code they are for functions and variables only.

That’s not how require work. It’s like trying to pass information into #include<module.h>. Why not pass these via function argument? What are you even trying to use require for? Why do you need to get the information from the loader of the module?

This will throw an error because function is a reserved keyword.

I’m using require for my new model but for now I’m just using it from workspace as I haven’t finished it. image

I didnt test it just make function f in everything and it will work.

Turns out since I used the assetid of the module instead of game.workspace to grab the module, part of it isn’t working. It was working fine before.

workspace in game.workspace needs a capital “w”

No it doesn’t. Workspace is deprecated and you should use workspace.

On-topic, I’m not sure what you want but if you want to get information from a module:

local Module = {
	Product1 = {ID = 0, MoreInfo = 392382}, 
	["Product 2"] = {ID = 1, MoreInfo = 234782832}
}

return Module

And then to access it:

local Module = require(path.to.module)
print(Module.Product1.ID) --> 0
print(Module["Product 2"].ID) --> 1
2 Likes

I meant that if you have game. before it then workspace needs a capital “w”, but if it is just workspace then a lowercase “w”.

image

I potentially have a solution but it is very basic
So in your module function add 2 new value after “Path”
change require(workspace.MainModule):Fire(game.workspace) with require(workspace.MainModule):Fire(game.workspace,0000000,true)

You see, require() is only designed to ONLY return what required ModuleScript returns.
If you want to pass more information into a function ModuleScript returns, you need to implement more arguments into that function. If you want us to help with that, you’ll need to provide code inside your ModuleScript.

1 Like

So I see you get the Module Script by id so lets say you created the Module Script in studio example

local ModuleScript = {}

function ModuleScript:Fire(gamepass,donateuiperks)
      --Your code here now you get get gamepass and donateuiperks
end

return ModuleScript

Okay now I finished creating the module script now let’s use it create a Script and add the following code

local gamepass = 0000000 -- GamepassID

local donateuiperks = true -- Support DonateUI with allowing users to have donator perks from DonateUI <3

local MyModule = require(game.Workspace.ModuelScript) --You passed in Id that is also fine but in my case I am going to assume the module script is in workspace and it is named ModuelScript

MyModule:Fire(gamepass ,donateuiperks ) --Here i am using the Fire function I created in the table called MyModule now it will go through
``
1 Like

Thanks for the reply everyone,
I am currently trying my best to understand everything and I think it will be easier for me to process if there were references to what I am using.

https://www.roblox.com/library/5248418567/DonateUI-Module - Module
https://www.roblox.com/library/5248677580/DonateUI-Loader - Loader

https://www.roblox.com/library/5248418567/DonateUI-Module - Module
https://www.roblox.com/library/5248677580/DonateUI-Loader - Loader

1 Like

Alright, you can include 2 additional parameters here in the main module:

function module:Fire(Path, GamepassID, DonatePerk)

Then, you need to create 2 values (with regular Explorer window) inside the DonateUI package, a BoolValue and a IntValue. When the function is called, set their values:

TheGroup.IntValue.Value = GamepassID
TheGroup.BoolValue.Value = DonatePerk

And in the “Core” script, you reference some values the way we need:

local donateuidonorperks = script.Parent.BoolValue.Value
local gamepassId = script.Parent.IntValue.Value

Finally, in the loader, add your new parameters to one we have:

require(workspace.MainModule):Fire(game.workspace, gamepass, donateuiperks)

From what I see here, you’re trying to parse variables back into the module when you load it

You can do this by making your module return a function

--Forward Declarations so other functions can use the variables
local arg1
local arg2

return function(vArg1, vArg2)
   arg1 = vArg1
   arg2 = vArg2
end

Now when you require the module, you can do

require(module)("foo", "bar")

The default Chat service uses this way of parsing variables quite commonly to parse the chatservice into the API modules (ChatSpeaker, ChatChannel, etc.)