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?
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?
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 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.
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
``
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.
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:
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.)