How can I share a table between different environments? (plugin & server)

I have a module script with a table in it where I get and change content (data)

-- ModuleScript

local module = {}
local data = {}
function module.WriteData(content)
    table.insert(data, content)
end
function module.GetData()
    return data
end
return module

But I can’t see the changes made to the table when requiring the module from different environments

-- Server

local module = require(path)
module.WriteData(5)
print(module.GetData()) -- [ 5 ]


-- Another "server" environment (plugin or game console)

local module = require(path)
-- Data already written by the Server script
print(module.GetData()) -- [ ]

_G and shared don’t work because those are intended for same context levels, and SharedTables don’t let me save Instances data types in it. Help :sob:

1 Like

Also I guess Roblox doesn’t allow this at all for the client-server security and stuff, but for my specific case I think it’s just fine so I would say there should be an easy or at least well known method but I can’t find it anywhere

you may use the DataStore to preserve the data

It isn’t ideal but bindables allow you to cross this boundary, you can write a wrapper to handle this for you.

1 Like

Try using sharedTables with instance serialization.
You can use buffers or other serialization methods to do this, I think sharedTables support buffers.
Hope it helps.

1 Like