Advertisement
Guest User

Fixed Datastore2 inventory

a guest
Feb 23rd, 2020
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.55 KB | None | 0 0
  1. local datastore2 = require(1936396537)
  2. local invfunc
  3.  
  4. datastore2.Combine("InvTest", "Inventory")
  5.  
  6. game.Players.PlayerAdded:Connect(function(playeradded)
  7.     local inventory = datastore2("Inventory", playeradded)
  8.    
  9.     local invstat = Instance.new("StringValue")
  10.     invstat.Name = "Item"
  11.     invstat.Value = inventory:Get("A")
  12.    
  13.     inventory:OnUpdate(function(newsteps)
  14.         print(tostring("changed: "..newsteps))
  15.     end)
  16.    
  17.     if inventory:IsBackup() then
  18.         inventory:ClearBackup()
  19.     end
  20. end)
  21.  
  22.  
  23. function invfunc(player)
  24.     coroutine.resume(coroutine.create(function()
  25.         local inventory = datastore2("Inventory", player)
  26.         local str = inventory:Get()
  27.         warn(str)
  28.         if string.len(str) <= 1 then
  29.             game.ServerStorage.Items.A:Clone().Parent = game.Players[player.Name].Backpack
  30.         else
  31.             for i = 1, string.len(str) do
  32.                 print(string.sub(str, i,i))
  33.                 if game.ServerStorage.Items:FindFirstChild(string.sub(str, i,i)) then
  34.                     warn("found!")
  35.                     game.ServerStorage.Items[string.sub(str, i,i)]:Clone().Parent = game.Players[player.Name].Backpack
  36.                 end
  37.             end
  38.         end
  39.     end))
  40. end
  41.  
  42. game.ReplicatedStorage.Load.OnServerEvent:Connect(function(playertoload)
  43.     invfunc(playertoload)
  44. end)
  45.    
  46. game.ServerStorage.Events.AddItem.Event:Connect(function(playertostep, amount)
  47.     local stepstore = datastore2("Inventory", playertostep)
  48.     local str2 = stepstore:Get()
  49.     stepstore:Set(tostring(str2..amount))
  50. end)
  51.    
  52. game.ServerStorage.Events.ClearItems.Event:Connect(function(playertoclear)
  53.     local invstore = datastore2("Inventory", playertoclear)
  54.     invstore:Set("A")
  55. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement