Hello everyone, I am making a system in which any server script can call the function _G.LoadDataStore(key) and get the table saved in there. And if they call _G.SaveDataStore(key,data) they can save the data in the selected key. Would this script work?
local DataStore = game:GetService("DataStoreService"):GetDataStore("PlayerStats")
_G.LoadDataStore = function(key)
local SavedValues = DataStore:GetAsync(key)
if SavedValues then
return SavedValues
else
return "NoData"
end
end
_G.SaveDataStore = function(key, data)
DataStore:SetAsync(key, data)
end
Another script:
local DataToSave = {50, 30, 60}
_G.SaveDataStore("player_1234, DataToSave)
Would the data save?
Another Script:
local LoadedData = _G.LoadDataStore("player_1234")
print(LoadedData[1])
Would the data in the first position in the table of that datastore displayed inside the console?

2 comments
Thanks, and yes, I am using the UserId as key, this helped me a lot!!!
Happy to have helped :)