Advertisement
Quoteory

Data

Aug 19th, 2019
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.24 KB | None | 0 0
  1. -- Player Data Service
  2. -- Quoteory
  3. -- August 4, 2019
  4.  
  5. local PlayerDataService = {Client = {}}
  6. local serverScriptService
  7. local DataStore2
  8. local tableUtil
  9.  
  10. local defaultDataTable = {Stats = {Rank = 1, RankEXP = 0}, Plot = {Type = 1}} -- metatable
  11.  
  12. local PLAYER_DATASTORE = "PlayerData2"
  13. local playerDataCaches = {}
  14.  
  15.  
  16. function PlayerDataService:SetupData(Player)
  17.    
  18.     local dataStore = DataStore2(PLAYER_DATASTORE, Player)
  19.    
  20.     local loadedData = dataStore:GetTable(defaultDataTable)
  21.     local Temp = {}
  22.    
  23.     tableUtil.Print(loadedData, " ", true)
  24.    
  25.     playerDataCaches[Player] = {dataCache = loadedData, tempCache = Temp}
  26.    
  27.  
  28. end
  29.  
  30. function PlayerDataService:GetData(Player)
  31.     return playerDataCaches[Player]
  32. end
  33.  
  34. function PlayerDataService:SaveData(Player)
  35.     local dataStore = DataStore2(PLAYER_DATASTORE, Player)
  36.     dataStore:Set(playerDataCaches[Player].dataCache)  
  37. end
  38.  
  39. function PlayerDataService:ClearData(Player)
  40.     playerDataCaches[Player] = nil
  41. end
  42.  
  43.  
  44. function PlayerDataService:Start()
  45.    
  46. end
  47.  
  48.  
  49. function PlayerDataService:Init()
  50.     tableUtil = self.Shared.TableUtil
  51.     serverScriptService = game:GetService("ServerScriptService")
  52.     DataStore2 = require(serverScriptService:WaitForChild("DataStore2"))
  53. end
  54.  
  55.  
  56. return PlayerDataService
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement