SHARE
TWEET

help lmfao

a guest Jan 20th, 2020 84 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local InStudio = game:GetService("RunService"):IsStudio()
  2.  
  3. if not InStudio then
  4.     maindata = game:GetService("DataStoreService"):GetDataStore("StatsData")
  5. end
  6.  
  7. local function newdata()
  8.     return {
  9.         Level = 1,
  10.         Exp = 0,
  11.         Zanpakuto = 0,
  12.         ExpNeeded = 20,
  13.         Spinsleft = 4,
  14.         ShikaiUnlock = 0,
  15.         }
  16. end
  17.  
  18. function savedata(playerid, value)
  19.     if InStudio then return end
  20.  
  21.     local tries = 0
  22.     local success
  23.    
  24.     repeat tries = tries + 1
  25.         success = pcall(function()
  26.             maindata:SetAsync(playerid, value)
  27.         end)
  28.     if not success then wait(1) end
  29.     until tries == 3 or success
  30. end
  31.  
  32. local function loaddata(player)
  33.     local data
  34.     if InStudio then
  35.         data = newdata()
  36.         return data
  37.     else
  38.         local success = pcall(function()
  39.             data = maindata:GetAsync(tostring(player.userId))
  40.         end)
  41.        
  42.         if success then
  43.             if not data then
  44.                 data = newdata()
  45.             end
  46.             return data
  47.         else
  48.             print("datastore error!")
  49.             return nil
  50.         end
  51.    
  52.     end
  53. end
  54.  
  55. game.Players.PlayerAdded:connect(function(player)
  56.     local leader = Instance.new("Folder")
  57.     leader.Name = "stats"
  58.     leader.Parent = player
  59.    
  60.     local playerdata = loaddata(player)
  61.     if not playerdata then
  62.         leader:Destroy()
  63.         player:Kick("Issue loading data, please rejoin!")
  64.     return end
  65.    
  66.     print("isrunning")
  67.     for key,value in pairs(playerdata) do
  68.         local saveinstance = Instance.new("IntValue")
  69.         saveinstance.Name = tostring(key)
  70.         saveinstance.Value = value
  71.         saveinstance.Parent = leader
  72.     end
  73.     print("check2")
  74.    
  75. end)
  76.  
  77. local function createtable(folder)
  78.     local datatable = {}
  79.     for i,v in pairs(folder:GetChildren()) do
  80.         datatable[v.Name] = v.Value
  81.     end
  82.     return datatable
  83. end
  84.  
  85. game.Players.PlayerRemoving:Connect(function(player)
  86.     savedata(player.userId,createtable(player.stats))
  87. end)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top