Hello, I got a local script and I want to send the local player instance and character to the module script so I can get it in other scripts. How can I accomplish this?
essentially what im trying to do is I got two module scripts I want a local script to send the local player and character instance to the first module then send that data to the second module then that data be required by a server script
ModuleScripts can only be required or loaded separately.
So for example, if a server requires a ModuleScript, and the client requires the same module script, those loaded modules will be different, they won’t update in sync with each other’s information, if that makes sense. Essentially, each ModuleScript can have its own environment when required (server/client). Never both, that’s where RemoteEvents come into play.
But to answer your question, it might be easier to directly create some variables within the scope of your modules. Or, you could define like an :Init()
method if you really need to pass in arguments to it.
--//Variables only accessible by the module
local x = 4
local y = 5
return {}
local anotherModule = {}
function anotherModule:Init(...)
local args = {...}
--//do stuff with args
end
return anotherModule
You cant send information from a local script to a module script. But you can send information from a module script to a local script. What I would recommend you to do is write code for the character in the module script function, and then require it inside the local script. Then call the function that you wrote inside your module script in your local script while passing the player character there. And write the code to send the data all inside the same module script, or require them both into the local script. Then you can just send a remote event to the server from the local script.