How to store a table in a modulescript

How would I store a table in a module script? I’ve tried this but it doesn’t seem to work.

local module = {}
module.inventory = nil

module.GotInventory = function(newinv)
	print("got inv")
	module.inventory = newinv 
	print(module.inventory)
end

module.GetInventory = function()
	print(module.inventory)
	if not module.inventory then
		warn("(Client) Waiting for inventory...")
		repeat wait() until module.inventory
	end
	
	return module.inventory
end

return module

ModuleScripts are required once per environment and then return a cached version. This would work as expected calling it twice in different LocalScript, but the console (CoreScripts) has it’s own environment. This means that a LocalScript calling GotInventory will properly set the inventory, but the separate instance of the module in console’s environment will not see the changes.

2 Likes