Advertisement
AnonymousHaxs

Nani?

Feb 25th, 2018
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.78 KB | None | 0 0
  1. local Players = game:GetService('Players')
  2. local Storage = game:GetService('ServerStorage')
  3. local DataHandler = require(script['DataHandler'])
  4. local Create = function(class, parent)
  5.     local instance = Instance.new(class);
  6.     return function(props)
  7.         for property, value in next, (props) do
  8.             if (property ~= 'Parent') and (typeof(value) ~= 'Instance') then
  9.                 local suc, err = pcall(function()
  10.                     instance[property] = value
  11.                 end)
  12.                
  13.             elseif (property == 'Parent') then
  14.                 parent = value
  15.             end
  16.         end
  17.        
  18.         if parent and (typeof(parent) == 'Instance') then
  19.             instance['Parent'] = parent
  20.         end
  21.        
  22.         return instance
  23.     end
  24. end
  25.  
  26.  
  27.  
  28. local Data = DataHandler '[A1-OUR-LORD-AND-SAVIOUR] 152';
  29. local OldStats    = DataHandler 'LeaderstatsDataStore';
  30. local OldTools    = DataHandler 'WeaponDataStore';
  31. local Blacklist   = {
  32.     Membership = true;
  33. }
  34.  
  35. local function Enter(Client)
  36.     local Key = Data.parse('[INF]:-', Client, 'UserId')
  37.     local GStored, Stored = Data.get(Key)
  38.     local Server = Data.proxy[Key]
  39.    
  40.     if not Stored and not Server then
  41.         local GLevel, Level = OldStats.get('level_' .. Client['UserId'])
  42.         local GXP, XP = OldStats.get('xp_' .. Client['UserId'])
  43.         local GGold, Gold = OldStats.get('gold_' .. Client['UserId'])
  44.         local GRebirth, Rebirth = OldStats.get('rebirth_' .. Client['UserId'])
  45.        
  46.         Data.set(Key, {
  47.             Level = (GLevel and Level) or 1;
  48.             XP = (GXP and XP) or 0;
  49.             Gold = (GGold and Gold) or 0;
  50.             Rebirth = (GRebirth and Rebirth) or 0;
  51.             Tools = (function()
  52.                 local IHAVENTDIED, STRANDOFHAIR = OldTools.get("user_" .. Client['UserId'])
  53.                 local AHHHHHH = {}
  54.                                
  55.                 if IHAVENTDIED and STRANDOFHAIR then
  56.                     for PULL = 1, #STRANDOFHAIR do
  57.                         AHHHHHH[STRANDOFHAIR[PULL]] = true
  58.                     end
  59.                 end
  60.                
  61.                 return AHHHHHH
  62.             end)();
  63.         })
  64.     elseif not Stored and Server then
  65.         Data.set(Server)
  66.     elseif Stored then
  67.         Data.proxy[Key] = Stored
  68.     end
  69.    
  70.    
  71.     --local GL = Client:WaitForChild("IsGPLoaded")
  72.     --local DL = Client:WaitForChild("IsDataLoaded")
  73.    
  74.     local Loaded = Data.proxy[Key]
  75.     local Leader = Create('Folder', Client){
  76.         Name = 'leaderstats';
  77.     }
  78.    
  79.     Create('IntValue', Leader){
  80.         Name = 'Level';
  81.         Value = Loaded.Level
  82.     }
  83.    
  84.     Create('NumberValue', Leader){
  85.         Name = 'XP';
  86.         Value = Loaded.XP
  87.     }
  88.    
  89.     Create('NumberValue', Leader){
  90.         Name = 'Gold';
  91.         Value = Loaded.Gold
  92.     }
  93.    
  94.     Create('IntConstrainedValue', Leader){
  95.         Name = 'Rebirth';
  96.         MaxValue = 99;
  97.         Value = Loaded.Rebirth
  98.     }
  99.    
  100.     --repeat wait() until GL.Value
  101.     local Tools = (function()
  102.         local t= {}
  103.        
  104.         for __, Folder in next, (Storage:WaitForChild('Items'):GetChildren()) do
  105.             if not Blacklist[Folder['Name']] then
  106.                 for __, tool in next, (Folder:GetChildren()) do
  107.                     t[#t + 1] = tool
  108.                 end
  109.             end
  110.         end    
  111.        
  112.         return t
  113.     end)()
  114.    
  115.     for Name, Enabled in next, (Loaded.Tools) do
  116.         if Enabled then
  117.             for index = 1, #Tools do
  118.                 local Tool = Tools[index]
  119.                 if (Name == Tool['Name']) and not (Client.StarterGear:FindFirstChild(Tool['Name'])) then
  120.                     Tool:Clone().Parent = Client.StarterGear
  121.                 end
  122.             end
  123.         end
  124.     end
  125.    
  126.     --DL.Value = true
  127.     if Client.Character then
  128.         Client:LoadCharacter()
  129.     end
  130. end
  131.  
  132. local function Exit(Client)
  133.     local Key = Data.parse('[INF]:-', Client, 'UserId')
  134.     local Server = Data.proxy[Key]
  135.    
  136.     if Server then
  137.         local Names = {}
  138.         table.foreach(Client.StarterGear:GetChildren(),
  139.             function(_, Name)
  140.                 local Obj = Storage.Items:FindFirstChild(tostring(Name), true)
  141.                 local Ignore do            
  142.                     if Obj and Blacklist[Obj.Parent['Name']] then
  143.                         Ignore = true  
  144.                     end
  145.                 end
  146.                
  147.                 if not Ignore then
  148.                     Names[tostring(Name)] = true
  149.                 end
  150.             end
  151.         )
  152.        
  153.         local Leader = Client:WaitForChild('leaderstats')
  154.         Data.set(Key, {
  155.             Tools = Names;
  156.             Level = Leader.Level.Value;
  157.             XP = Leader.XP.Value;
  158.             Gold = Leader.Gold.Value;
  159.             Rebirth = Leader.Rebirth.Value;
  160.         })
  161.     end
  162.    
  163.     Data.proxy[Key] = nil
  164. end
  165.  
  166. for __, Player in next, (Players:GetPlayers()) do
  167.     Enter(Player)
  168. end
  169.  
  170. Players.PlayerAdded:Connect(Enter)
  171. Players.PlayerRemoving:Connect(Exit)
  172. game:BindToClose(function()
  173.     for __, Client in next, (Players:GetPlayers()) do
  174.         spawn(function()
  175.             local Key = Data.parse('[INF]:-', Client, 'UserId')
  176.             local Server = Data.proxy[Key]
  177.            
  178.             if Server then
  179.                 local Names = {}
  180.                 table.foreach(Client.StarterGear:GetChildren(),
  181.                     function(_, Name)
  182.                         local Obj = Storage.Items:FindFirstChild(tostring(Name), true)
  183.                         local Ignore do            
  184.                             if Obj and Blacklist[Obj.Parent['Name']] then
  185.                                 Ignore = true  
  186.                             end
  187.                         end
  188.                        
  189.                         if not Ignore then
  190.                             Names[tostring(Name)] = true
  191.                         end
  192.                     end
  193.                 )
  194.                
  195.                 local Leader = Client:WaitForChild('leaderstats')
  196.                 Data.set(Key, {
  197.                     Tools = Names;
  198.                     Level = Leader.Level.Value;
  199.                     XP = Leader.XP.Value;
  200.                     Gold = Leader.Gold.Value;
  201.                     Rebirth = Leader.Rebirth.Value;
  202.                 })
  203.             end
  204.         end)
  205.     end
  206. end)
  207.  
  208. while wait(300) do
  209.     warn('AUTO SAVE')
  210.     for __, Client in next, (Players:GetPlayers()) do
  211.         spawn(function()
  212.             local Key = Data.parse('[INF]:-', Client, 'UserId')
  213.             local Server = Data.proxy[Key]
  214.            
  215.             if Server then
  216.                 local Names = {}
  217.                 table.foreach(Client.StarterGear:GetChildren(),
  218.                     function(_, Name)
  219.                         local Obj = Storage.Items:FindFirstChild(tostring(Name), true)
  220.                         local Ignore do            
  221.                             if Obj and Blacklist[Obj.Parent['Name']] then
  222.                                 Ignore = true  
  223.                             end
  224.                         end
  225.                        
  226.                         if not Ignore then
  227.                             Names[tostring(Name)] = true
  228.                         end
  229.                     end
  230.                 )
  231.                
  232.                 local Leader = Client:WaitForChild('leaderstats')
  233.                 Data.set(Key, {
  234.                     Tools = Names;
  235.                     Level = Leader.Level.Value;
  236.                     XP = Leader.XP.Value;
  237.                     Gold = Leader.Gold.Value;
  238.                     Rebirth = Leader.Rebirth.Value;
  239.                 })
  240.             end
  241.         end)
  242.     end
  243. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement