Best way to use a table with a datastore?
Im really confused on how I can get all the values from a table and apply it to the player when joining and leaving.
Great Question!
The way I use tables with data stores is using a dictionary. A dictionary is basically a table where you define each index, and like normal tables all indexes should should be unique. A basic example of a dictionary can be seen here:
local Dictionary = { Index1 = "Value1"; Index2 = true; Index3 = 300000000; }
As you can see here, dictionaries can also have different data types within them. So these dictionaries can hold as little and as much information as a I please. Now, personally, whenever doing data stores I like to just save the dictionary right into the data store under the unique player key of course. That looks something like this:
local DataDictionary = { Level = 100; Gold = 100; DankNess = "Only Koolkid can be the dank"; }; local DataStore = game:GetService("DataStoreService"):GetDataStore("A Random Datastore") DataStore:SetAsync(DataKeyHere,DataDictionary);
By doing this we can alter DataDictionary however we please, and just simple save it to be loaded later.
THERE ARE LIMITATIONS THOUGH Roblox Datastores aren't able to save values like BrickColor or Color3. There is also the general data limit. If you try to save too often, roblox will throttle you, and if you try to save too much data into one key, it will become rather problematic.
Back to the point though Just like you saved that data, you can also load it with ease. Same way you load anything else
local DataStore = game:GetService("DataStoreService"):GetDataStore("A Random Datastore") local DataDictionary = DataStore:GetAsync(UnqiueDataKey);
Handling data this way opens up a windows of possibilities, and can make the data hassle almost non existent for the most part!
I hope my answer helped
~Lone