Re-setting the variables inside a ModuleScript using a script will not update it

I am working on a game that needs to store data in a table, I would use StringValue and parse it to JSON but it is slower and takes more lines of code.
I tried putting the data in a modulescript to require it with multiple scripts, but requiring the modulescripts returns the raw unedited value.

ModuleScript

local module = {}
module.data = {}

return module

ServerScript

local module = require(game.ReplicatedStorage.ModuleScript)
module.data[1] = "Test"

print(module.data[1]) -- Outputs "Test"

LocalScript

local module = require(game.ReplicatedStorage.ModuleScript)
print(module.data[1]) -- Outputs nil

As in my game, the serverscript runs first before the localscript so the localscript would be able to load the module script with its edited variables. But it just keeps returning the unedited value, how would I prevent this?
1 Like

ModuleScripts are not replicated. You would have to send the data between server and client manually.

Oh, that makes a lot of sense. I didn’t actually see the method of sending data from server to client cause I’m so stupid.

Thank you so much!

1 Like