Advertisement
Guest User

Untitled

a guest
Jan 18th, 2020
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.39 KB | None | 0 0
  1.  
  2. local ReplicatedStorage = game:GetService("ReplicatedStorage")
  3. local invUpdate = ReplicatedStorage:WaitForChild("invUpdate")
  4. local Inventory = {}
  5. local clientInv = {}
  6. local cService = game:GetService("CollectionService")
  7. local lastSlot = game.Players.LocalPlayer.PlayerGui:WaitForChild("Inventory").LastSlot
  8. slots = cService:GetTagged("invSlot")
  9.  
  10. --Non Modules
  11. function invCheck(inv)
  12.     if #clientInv == 0 then
  13.     print("There is nothing in the client's Inventory.")
  14.     clientInv = inv
  15.     for i,v in pairs(clientInv) do
  16.     if #slots == 0 then
  17.         newSlot(i,v)
  18.     else addSlots(i,v)
  19.     end
  20.     end
  21.     end
  22. end
  23.  
  24.  
  25. --Modules
  26.  
  27. function newSlot(name,value)
  28. local scrollingFrame = game.Players.LocalPlayer.PlayerGui.Inventory.invFrame
  29. local firstText = Instance.new("TextButton")
  30. firstText.Name = name
  31. firstText.Parent = scrollingFrame
  32. firstText.Position = UDim2.new(.05, 0,.05, 0)
  33. firstText.Size = UDim2.new(.8, 0, .05, 0)
  34. firstText.BackgroundColor3 = Color3.new(255/255, 235/255, 168/255)
  35. firstText.ZIndex = 2
  36. firstText.Text = name.." - "..value
  37. cService:AddTag(firstText,"invSlot")
  38. scrollingFrame.Parent.LastSlot.Value = name
  39. local constraint = Instance.new("UISizeConstraint")
  40. constraint.Parent = firstText
  41. constraint.MaxSize = Vector2.new(250,50)
  42. print("new item"..name)
  43. end
  44.  
  45. function addSlots(itemName,itemValue)
  46. local scrollingFrame = game.Players.LocalPlayer.PlayerGui.Inventory.invFrame
  47. cService:GetTagged("invSlots")
  48. local nextText = Instance.new("TextButton")
  49. nextText.Name = itemName
  50. nextText.Position = lastSlot.Position+UDim2.new(0, 0, 0.055, 0)
  51. nextText.Size = lastSlot.Size
  52. nextText.BackgroundColor3 = lastSlot.BackgroundColor3
  53. nextText.ZIndex = 2
  54. nextText.Parent = scrollingFrame
  55. nextText.Text = itemName.." - "..itemValue
  56. cService:AddTag(nextText,"invSlot")
  57. local constraint = Instance.new("UISizeConstraint")
  58. constraint.Parent = nextText
  59. constraint.MaxSize = Vector2.new(250,50)
  60. scrollingFrame.Parent.LastSlot.Value = nextText.Name
  61. print("AddSlot Loaded")
  62. print(nextText.Name.. " and ".. scrollingFrame.Parent.LastSlot.Value)
  63. local scrollSizeY = game.Players.LocalPlayer.PlayerGui.Inventory.invFrame.CanvasSize.Y.Scale
  64. local scrollPosY = game.Players.LocalPlayer.PlayerGui.Inventory.invFrame.Position.Y.Scale
  65. print(nextText.Position.Y.Scale)
  66. if nextText.Position.Y.Scale > scrollPosY+(scrollSizeY-nextText.Position.Y.Scale) then
  67.     game.Players.LocalPlayer.PlayerGui.Inventory.invFrame.CanvasSize=game.Players.LocalPlayer.PlayerGui.Inventory.invFrame.CanvasSize+UDim2.new(0,0,0,50)
  68.     print("AddSlot End")
  69. else
  70.      print("AddSlot End")
  71. end
  72. end
  73.  
  74.  
  75.  
  76.  
  77. function Inventory.UpdateSlots(remName)
  78. if #slots == 0 then
  79.     print("There is nothing left in the inventory")
  80. else  do
  81. for i,v in pairs(slots)do
  82.     if v.Name == remName then
  83.         print(v.Name.."="..remName)
  84.         print(remName.Name.."being destroyed")
  85.         wait(2)
  86.         remName:Destroy()
  87.         print("destroyed")
  88. end
  89. end
  90. end
  91. end
  92. end
  93. function Inventory.AddSlot(itemName,itemValue)
  94. print("Received Data from GetData")
  95. for i,v in ipairs(slots) do
  96.     if v == itemName then
  97.         v.Text = itemName.." - "..itemValue
  98.    
  99.     else do
  100.          addSlots(itemName,itemValue)
  101.     end
  102.     end
  103.  
  104. end
  105. end
  106.  
  107. function onInvUpdate(player,inventory)
  108.     if player == game.Players.LocalPlayer then
  109.     print(player.Name.." = "..game.Players.LocalPlayer.Name)
  110.     print("Updating Client Inventory")
  111.     invCheck(inventory)
  112.     end
  113. end
  114.  
  115. invUpdate.OnClientEvent:Connect(onInvUpdate)
  116. return Inventory
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement