Using Arrays For Data Store?
Asked by
6 years ago Edited 6 years ago
I am in the process of developing a script that saves player data. This is a portion of how the data is loaded in when the player joins:
01 | local DataStoreService = game:GetService( "DataStoreService" ) |
02 | local ServerData = { 0 , 0 , 0 , 0 , 0 , 0 , 0 } |
03 | local DataStore 1 = DataStoreService:GetDataStore( "CnsData" ..version) |
04 | local DataStore 2 = DataStoreService:GetDataStore( "StrData" ..version) |
05 | local DataSto.... (you get the point) |
07 | local DataFetchSuccess,ErrorMessage = pcall ( function () |
08 | ServerData [ 1 ] = DataStore 1 :GetAsync( tostring (Player.UserId)) |
09 | ServerData [ 2 ] = DataStore 2 :GetAsync( tostring (Player.UserId)) |
10 | ServerData [ 3 ] = DataStore 3 :GetAsync( tostring (Player.UserId)) |
11 | ServerData [ 4 ] = DataStore 4 :GetAsync( tostring (Player.UserId)) |
12 | ServerData [ 5 ] = DataStore 5 :GetAsync( tostring (Player.UserId)) |
13 | ServerData [ 6 ] = DataStore 6 :GetAsync( tostring (Player.UserId)) |
14 | ServerData [ 7 ] = DataStore 7 :GetAsync( tostring (Player.UserId)) |
This system works fine. The data is loaded from the server into an array within the script. I would like to know if it is possible to place the data calls in an array like this:
1 | local DataStore = { DataStoreService:GetDataStore( "example" ..version), |
2 | DataStoreService:GetDataStore( "example1" ..version), ect } |
With this I would think it's possible to load the data like this:
1 | local DataFetchSuccess,ErrorMessage = pcall ( function () |
3 | ServerData [ i ] = DataStore [ i ] |
This is how I originally had programmed it but nothing would save or load. Is there something I can fix to make this possible?