Issues with loading data from a Datastore

  1. What do you want to achieve? Keep it simple and clear!

    I am making a house building system. Where you can build them as a player and decorate them as you like. All this information will be stored in a player dictionary in a DataStore, the problem comes when loading this information, which I hope will be big, not huge, but a little bit depending on the player.

  2. What is the issue? Include screenshots / videos if possible!

Long Story

I have an inventory system, this works by loading the information through objects, for example, an object where the key name of the tool is stored, another one where all the modifications of the tool are stored. Doing this to load 5 houses I don’t think is the solution, firstly creating each object would take time and would make the loading times huge, and secondly the amount of objects on the server I don’t think is any good.

So I would like to store it in a global table, something like _G, the problem is that I’m not sure how to do it. I have seen on the forum people using a modulescript with two functions, one to read and one to write, but I see the problem that a queue system should be implemented, as it could happen the case where two scripts get the information and then decide to write to it. Only the one that wrote last would be the one that would keep its information and that is a serious problem.

The best way according to my knowledge would be through _G, but I don’t understand how to put a table inside it, one that looks something like this:

_G.Houses["Player1"] = {
	["House1"] = {
		["Wall_Type_A"] = {
			["Position"] = CFrame.new(); -- Grid_Position
			["Paint"] = Color3.new(1,1,1);
		};
		["Light"] = {
			["Position"] = CFrame.new(); -- Grid_Position
			["Color"] = Color3.new(1,1,1);
		};
	};
	["House2"] = {
		["Wall_Type_B"] = {
			["Position"] = CFrame.new(); -- Grid_Position
			["Paint"] = Color3.new(1,1,.5);
		};
		["Light"] = {
			["Position"] = CFrame.new(); -- Grid_Position
			["Color"] = Color3.new(1,1,1);
		};
	}
};
}
Short Story

I need to load data from a datastore, which looks like this:

_G.Houses["Player1"] = {
  ["House1"] = {
  	["Wall_Type_A"] = {
  		["Position"] = CFrame.new(); -- Grid_Position
  		["Paint"] = Color3.new(1,1,1);
  	};
  	["Light"] = {
  		["Position"] = CFrame.new(); -- Grid_Position
  		["Color"] = Color3.new(1,1,1);
  	};
  };
  ["House2"] = {
  	["Wall_Type_B"] = {
  		["Position"] = CFrame.new(); -- Grid_Position
  		["Paint"] = Color3.new(1,1,.5);
  	};
  	["Light"] = {
  		["Position"] = CFrame.new(); -- Grid_Position
  		["Color"] = Color3.new(1,1,1);
  	};
  }
};
}

And that it must meet these requirements:

  1. Be efficient and fast

  2. Be accessible from any server script

  3. That you can write in it at any time without any queue

  4. That you can read at any time

Any help is welcome.

Thank you very much,

Bruno

1 Like