I have been working on my own set of DataStore functions for anything I might need.
At the moment it can:
- Save Models (Via my own Module)
- Load Models (Via my own Module)
- Save unlimited data that can be accessed similarly to an array (Within some limits, This is also used to create backups)
- Basic Stuff (Save, Load, Update, Array Save/Load)
(Edit: Added a limit to number of attempts on my studio version)
.
My DSS Functions
local DataStoreService = game:GetService("DataStoreService")
----------------------------------------- // Base Functions (Save, Load, Update, Remove, CheckForData)
function SetData(Store,Player,Data)
while true do
local S, R = pcall(function()
local NewStore = DataStoreService:GetDataStore(Store)
NewStore:SetAsync(Player,Data)
end)
if S then
print("Set Data")
break
else
print("DSS Error:")
print(R)
wait(2)
end
end
end
function UpData(Store,Player,Data)
while true do
local S, R = pcall(function()
local NewStore = DataStoreService:GetDataStore(Store)
NewStore:UpdateAsync(Player,Data)
end)
if S then
break
else
print("DSS Error:")
print(R)
wait(2)
end
end
end
function GetData(Store,Player)
local Result
while true do
local S, R = pcall(function()
local NewStore = DataStoreService:GetDataStore(Store)
Result = NewStore:GetAsync(Player)
end)
if S then
return Result
else
print("DSS Error:")
print(R)
wait(2)
end
end
end
function RemoveData(Store,Player)
while true do
local S, R = pcall(function()
local NewStore = DataStoreService:GetDataStore(Store)
NewStore:RemoveAsync(Player)
end)
if S then
print("Removed Data")
break
else
print("DSS Error:")
print(R)
wait(2)
end
end
end
function CheckForExistingData(Store,Player)
local Data
for i = 1,#3 do
local S, R = pcall(function()
Data = GetData(Store,Player)
if Data == nil then
local Result = false
return Result
else
end
end)
wait(1)
if S then
break
end
end
if Data == nil then
local Result = true
return Result
end
end
----------------------------------------- // ArraySaving, ArrayLoading
function SaveArray(Store,Player,Data)
local Combined = table.concat(Data,";Split;")
SetData(Store,Player,Data)
end
function LoadArray(Store,Player)
return string.split(GetData(Store,Player),";Split;")
end
----------------------------------------- // DataStore Listing (For BackUps or Databases)
function CreateListing(Store,Data)
while true do
local S, R = pcall(function()
local EntryCount = GetData(Store .. "EntryCount","EntryCount")
if tonumber(EntryCount) == nil then
EntryCount = 0
end
EntryCount = tostring(tonumber(EntryCount) + 1)
SetData(Store,EntryCount,Data)
SetData(Store .. "EntryCount","EntryCount",EntryCount)
end)
if S then
break
else
print("DSS Error:")
print(R)
wait(2)
end
end
end
function GetListings(Store)
local StoreNames
while true do
local S, R = pcall(function()
local EntryCount = GetData(Store .. "EntryCount","EntryCount")
EntryCount = tonumber(EntryCount)
StoreNames = {}
for i = 1, EntryCount do
local Name = tostring(i)
local Check = CheckForExistingData(Store,tostring(i))
if Check == true then
table.insert(StoreNames,Name)
end
end
end)
if S then
return StoreNames
else
print("DSS Error:")
print(R)
wait(2)
end
end
end
function RemoveListing(Store,Number)
SetData(Store,Number,nil)
end
function GetEntryCount(Store)
local EntryCount = GetData(Store .. "EntryCount","EntryCount")
EntryCount = tonumber(EntryCount)
return EntryCount
end
----------------------------------------- // Save Or Load Models (Via My Modules)
local PartSavingMod = require(script.PartSavingModule)
function SaveModel(Model)
return PartSavingMod.GetModelProperties(Model)
end
local PartLoadMod = require(script.PartLoadingModule)
function LoadModel(Model)
return PartLoadMod.LoadModel(Model)
end