Modules are not used as a form of saving mechanism, they are used as a DRY principle. DRY is basically just the rule of “don’t-repeat-yourself”, defining behavior and allowing you to access key principles of your code. For example when I am using my auto ranking bots I use modules in order to hold the settings which I may want to call elsewhere.
You essentially have changed the value for your copy of the “Electro.Network” and then because its not saved it has basically just been lost to the abyss, it doesn’t have any pointer (a constant or variable) to refer to. As such when you do the next line you have required a new version of the module.
What you may want to use instead is a simple table inside a script. Modules are used explicitly for containers that run once and returns your entire modules commands etc.
How it should be used as an example:
-- A module which can be used for creating an immunity system for players in the Immune list.
local module = {}
module.ImmunePlayers = {}
function module:CheckImmunity(name)
for _, player in pairs(module.ImmunePlayers) do
if player == name then return true end
end
return false
end
return module
Always returns the same type of value, can be applied in many ways. If you need any help feel free to reply to this. Modules are great though, can be a good skill to use when you need it.
local Net = require(game.ServerScriptService.Game.Electro.Network)
Net.Activity[50] = true
And then operate off of that without deleting the memory pointer then you’ll be fine.
Also a global variable in a programming sense is just a variable which sits outside all functions etc. If your talking about script-to-script variables then use _G, its basically a default module.
A module script will run only once - the first time require is called on it. It’s return value is cached so any require calls made afterwards will return the same value. So if a module script returns a table, and a script requires that module and modifies the table, the change will be visible to other scripts that require the same module later on.
If you are running a console command to change a value, then running another command after to read the value it shouldn’t work because the execution environment is different. If you try it in actual scripts and run the game it should work.
Example ModuleScript in game.Workspace:
return {}
Example Script1 in game.Workspace:
local data = require(workspace.ModuleScript)
while (true) do
wait(1)
print(data["test"])
end
Example Script2 in game.Workspace:
local data = require(workspace.ModuleScript)
wait(5)
data["test"] = "hello"
The output would be something like:
-- nil
-- nil
-- nil
-- nil
-- (the table is modified here)
-- hello
-- hello
-- hello...
No, whatever is returned by a module script is shared as long as you’re not crossing the client-server boundary. (i.e. if you try to use a server script to access something that was set by a local script)