Advertisement
minimic2002

Minis DSS Module

Jan 25th, 2025
17
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.53 KB | None | 0 0
  1. local DSS3 = {}
  2.  
  3. local DataStoreService = game:GetService("DataStoreService")
  4.  
  5. local RunService = game:GetService("RunService")
  6.  
  7. ----------------------------------------- // Base Functions (Save, Load, Update, Remove, CheckForData)
  8.  
  9. function DSS3.SetData(Store,Player,Data)
  10. for i = 1,10 do
  11. local S, R = pcall(function()
  12. local NewStore = DataStoreService:GetDataStore(Store)
  13. NewStore:SetAsync(Player,Data)
  14. end)
  15. if S then
  16. print("Set Data")
  17. break
  18. else
  19. print("DSS Error:")
  20. print(R)
  21. wait(2)
  22. end
  23. end
  24. end
  25.  
  26. function DSS3.UpData(Store,Player,Data)
  27. for i = 1,10 do
  28. local S, R = pcall(function()
  29. local NewStore = DataStoreService:GetDataStore(Store)
  30. NewStore:UpdateAsync(Player,Data)
  31. end)
  32. if S then
  33. break
  34. else
  35. print("DSS Error:")
  36. print(R)
  37. wait(2)
  38. end
  39. end
  40.  
  41. end
  42.  
  43. function DSS3.GetData(Store,Player)
  44. local Result
  45. for i = 1,10 do
  46. local S, R = pcall(function()
  47. local NewStore = DataStoreService:GetDataStore(Store)
  48. Result = NewStore:GetAsync(Player)
  49.  
  50. end)
  51. if S then
  52. return Result
  53. else
  54. print("DSS Error:")
  55. print(R)
  56. wait(2)
  57. end
  58. end
  59.  
  60. end
  61.  
  62. function DSS3.RemoveData(Store,Player)
  63. for i = 1,10 do
  64. local S, R = pcall(function()
  65. local NewStore = DataStoreService:GetDataStore(Store)
  66. NewStore:RemoveAsync(Player)
  67. end)
  68. if S then
  69. print("Removed Data")
  70. break
  71. else
  72. print("DSS Error:")
  73. print(R)
  74. wait(2)
  75. end
  76. end
  77. end
  78.  
  79. function DSS3.CheckForExistingData(Store,Player)
  80. local Data
  81. for i = 1,#3 do
  82. local S, R = pcall(function()
  83. Data = DSS3.GetData(Store,Player)
  84. if Data == nil then
  85. local Result = false
  86. return Result
  87. else
  88.  
  89. end
  90. end)
  91.  
  92. wait(1)
  93. if S then
  94. break
  95. end
  96. end
  97. if Data == nil then
  98. local Result = true
  99. return Result
  100. end
  101. end
  102. ----------------------------------------- // ArraySaving, ArrayLoading
  103. function DSS3.SaveArray(Store,Player,Data)
  104. local Combined = table.concat(Data,";Split;")
  105. DSS3.SetData(Store,Player,Data)
  106. end
  107.  
  108. function DSS3.LoadArray(Store,Player)
  109. return string.split(DSS3.GetData(Store,Player),";Split;")
  110. end
  111.  
  112. ----------------------------------------- // DataStore Listing (For BackUps or Databases)
  113. function DSS3.CreateListing(Store,Data)
  114. for i = 1,10 do
  115. local S, R = pcall(function()
  116. local EntryCount = DSS3.GetData(Store .. "EntryCount","EntryCount")
  117. if tonumber(EntryCount) == nil then
  118. EntryCount = 0
  119. end
  120. EntryCount = tostring(tonumber(EntryCount) + 1)
  121. DSS3.SetData(Store,EntryCount,Data)
  122. DSS3.SetData(Store .. "EntryCount","EntryCount",EntryCount)
  123.  
  124. end)
  125. if S then
  126. break
  127. else
  128. print("DSS Error:")
  129. print(R)
  130. wait(2)
  131. end
  132. end
  133.  
  134. end
  135.  
  136. function DSS3.GetListings(Store)
  137. local StoreNames = {}
  138. for i = 1,10 do
  139. local S, R = pcall(function()
  140. local EntryCount = DSS3.GetData(Store .. "EntryCount","EntryCount")
  141. EntryCount = tonumber(EntryCount)
  142. StoreNames = {}
  143. for i = 1, EntryCount do
  144. local Name = tostring(i)
  145. table.insert(StoreNames,Name)
  146. end
  147. end)
  148. if S then
  149. return StoreNames
  150. else
  151. print("DSS Error:")
  152. print(R)
  153. wait(2)
  154. end
  155. end
  156.  
  157.  
  158. end
  159.  
  160. function DSS3.RemoveListing(Store,Number)
  161. DSS3.SetData(Store,Number,nil)
  162. end
  163.  
  164. function DSS3.GetEntryCount(Store)
  165. local EntryCount = DSS3.GetData(Store .. "EntryCount","EntryCount")
  166. EntryCount = tonumber(EntryCount)
  167. return EntryCount
  168. end
  169.  
  170.  
  171. ----------------------------------------- // Save Or Load Models (Via My Modules)
  172. local PartSavingMod = require(script.PartSavingModule)
  173. function DSS3.SaveModel(Model)
  174. return PartSavingMod.GetModelProperties(Model)
  175. end
  176.  
  177. local PartLoadMod = require(script.PartLoadingModule)
  178. function DSS3.LoadModel(Model)
  179. return PartLoadMod.LoadModel(Model)
  180. end
  181.  
  182.  
  183. ----------------------------------------- // Time And Date
  184. local TimeAndDateMod = require(script.TimeAndDateMod)
  185.  
  186. function DSS3.GetSecondsPassed()
  187. return TimeAndDateMod.SecondTime()
  188. end
  189.  
  190. ----------------------------------------- // GetBackup Data
  191. function DSS3.GetBackup(Store)
  192. print("Attempting To Get Backup Data from" .. Store)
  193. local Backups = DSS3.GetListings(Store)
  194. local Data = {}
  195. Data[1] = #Backups
  196. while Data[3] ~= nil do
  197. Data[2] = DSS3.GetData(Backups[Data[1]])
  198. if Data[2] == nil then
  199. -- Data May Be Corrupted
  200. Data[1] = Data[1] - 1
  201. else
  202. Data[3] = Data[2]
  203. end
  204. end
  205.  
  206. if Data[3] then
  207. return Data[3]
  208. else
  209. print("No Usable Backups Found")
  210. end
  211. end
  212.  
  213. ----------------------------------------- // Returns The DSS3 Module
  214. return DSS3
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement