Guest User

datastore2

a guest
Sep 5th, 2017
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.67 KB | None | 0 0
  1. local module = {}
  2. local DataStoreService = game:GetService("DataStoreService")
  3. local InventoryItems = DataStoreService:GetDataStore("ToolDataStore")
  4. AUTOSAVE_INTERVAL = 120
  5.  
  6. game.Players.PlayerAdded:Connect(function(Player)
  7.     local Key = "PlayerIdNum-"..Player.UserId.."_ToolItems"
  8.     --remove createdata and get data functions
  9.     --leaderstats
  10.     local inew = Instance.new
  11.    
  12.     local ls = inew("Folder")
  13.     ls.Name = "leaderstats"
  14.     ls.Parent = Player
  15.    
  16.     local points = inew("IntValue")
  17.     points.Name = "Points"
  18.     points.Parent = ls
  19.    
  20.     local experience = inew("IntValue")
  21.     experience.Name = "Experience"
  22.     experience.Parent = ls
  23.    
  24.     local wins = inew("IntValue")
  25.     wins.Name = "Wins"
  26.     wins.Parent = ls
  27.    
  28.     local kills = inew("IntValue")
  29.     kills.Name = "Kills"
  30.     kills.Parent = ls
  31.    
  32.     local level = inew("IntValue")
  33.     level.Name = "Level"
  34.     level.Parent = ls
  35.    
  36.     local heropoints = inew("IntValue")
  37.     heropoints.Name = "HeroPoints"
  38.     heropoints.Parent = ls
  39.    
  40.     local raidwins = inew("IntValue")
  41.     raidwins.Name = "RaidWins"
  42.     raidwins.Parent = ls
  43.     --Inventory
  44.     local InvData = Player:WaitForChild("Backpack"):WaitForChild("Inventory")
  45.     local HasM9 = InvData:WaitForChild("HasM9")
  46.     local HasPistol = InvData:WaitForChild("HasPistol")
  47.     local HasM4 = InvData:WaitForChild("HasM4")
  48.     local HasShotgun = InvData:WaitForChild("HasShotgun")
  49.     local HasSuperball = InvData:WaitForChild("HasSuperball")
  50.     local HasRocketLauncher = InvData:WaitForChild("HasRocketLauncher")
  51.     local HasGoldenGun = InvData:WaitForChild("HasGoldenGun")
  52.     local HasBombthrower = InvData:WaitForChild("HasBombthrower")
  53.     local HasAK = InvData:WaitForChild("HasAK")
  54.     local HasFireball = InvData:WaitForChild("HasFireball")
  55.     --Saving Data
  56.     local StoreToSet = {}
  57.     local DataToGet = InventoryItems:GetAsync(Key)
  58.     if DataToGet ~= nil then
  59.         if #DataToGet >= 1 then
  60.             if DataToGet[1] ~= nil then
  61.                 HasM9.Value = DataToGet[1]
  62.                 table.insert(StoreToSet, DataToGet[1])
  63.             else
  64.                 DataToGet[1] = HasM9.Value
  65.                 HasM9.Value = false
  66.                 table.insert(StoreToSet, DataToGet[1])
  67.             end
  68.             if DataToGet[2] ~= nil then
  69.                 HasPistol.Value = DataToGet[2]
  70.                 table.insert(StoreToSet, DataToGet[2])
  71.             else
  72.                 DataToGet[2] = HasPistol.Value
  73.                 HasPistol.Value = false
  74.                 table.insert(StoreToSet, DataToGet[2])
  75.             end
  76.             if DataToGet[3] ~= nil then
  77.                 HasM4.Value = DataToGet[3]
  78.                 table.insert(StoreToSet, DataToGet[3])
  79.             else
  80.                 DataToGet[3] = HasM4.Value
  81.                 HasM4.Value = false
  82.                 table.insert(StoreToSet, DataToGet[3])
  83.             end
  84.             --ect (do the same for the rest of the values)
  85.         end
  86.     else
  87.         DataToGet = {}
  88.         DataToGet[1] = HasM9.Value
  89.         HasM9.Value = false
  90.         table.insert(StoreToSet, DataToGet[1])
  91.         DataToGet[2] = HasPistol.Value
  92.         HasPistol.Value = false
  93.         table.insert(StoreToSet, DataToGet[2])
  94.         DataToGet[3] = HasM4.Value
  95.         HasM4.Value = false
  96.         table.insert(StoreToSet, DataToGet[3])
  97.         --ect (do the same for the rest of the values)
  98.         print("New Data")
  99.     end
  100.     InventoryItems:SetAsync(Key, StoreToSet)
  101.     repeat wait() until Player.Character
  102.     if Player.Character and Player.Character:FindFirstChild("Humanoid") then
  103.         Player.Character.Humanoid.MaxHealth = 100 + (level.Value*10)
  104.     end
  105.     level.Changed:Connect(function(value)
  106.         if Player.Character and Player.Character:FindFirstChild("Humanoid") then
  107.             Player.Character.Humanoid.MaxHealth = 100 + (level.Value*10)
  108.         end
  109.     end)
  110.     Player.CharacterAdded:Connect(function(character)
  111.         character:WaitForChild("Humanoid").MaxHealth = 100 + (level.Value*10)
  112.     end)
  113.     local required = (level.Value*70)
  114.     experience.Changed:Connect(function()
  115.         if experience.Value >= required then
  116.             level.Value=level.Value+1
  117.             experience.Value = experience.Value-required
  118.         end
  119.     end)
  120. end)
Advertisement
Add Comment
Please, Sign In to add comment