Advertisement
HowToRoblox

InventoryGuiHandler

Nov 9th, 2021
3,047
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.56 KB | None | 0 0
  1. local button = script.Parent
  2. button.Position = UDim2.new(0.032, 0, 0.5, 0)
  3.  
  4. local open = false
  5.  
  6.  
  7. button.MouseButton1Click:Connect(function()
  8.    
  9.     open = not open
  10.    
  11.     local newPos = open and UDim2.new(0.319, 0, 0.5, 0) or UDim2.new(0.032, 0, 0.5, 0)
  12.        
  13.     button:TweenPosition(newPos, "InOut", "Quint", 0.5)
  14. end)
  15.  
  16.  
  17. local inventoryFolder = game.Players.LocalPlayer:WaitForChild("Inventory")
  18.  
  19.  
  20. function updateInv()
  21.    
  22.     for i, child in pairs(script.Parent.InventoryScroller:GetChildren()) do
  23.         if child:IsA("TextButton") then child:Destroy() end
  24.     end
  25.    
  26.     for i, item in pairs(inventoryFolder:GetChildren()) do
  27.        
  28.         if item.Value > 0 then
  29.        
  30.             local newButton = script.ItemButton:Clone()
  31.             newButton.ItemName.Text = item.Name
  32.             newButton.Count.Text = item.Value
  33.            
  34.             local cam = Instance.new("Camera", newButton.ItemFrame)
  35.             newButton.ItemFrame.CurrentCamera = cam
  36.            
  37.             local displayItem = game.ReplicatedStorage.Items[item.Name]:Clone()
  38.             displayItem.Parent = newButton.ItemFrame
  39.            
  40.             cam.CFrame = CFrame.new(displayItem.Position + displayItem.CFrame.LookVector * 4, displayItem.Position)
  41.            
  42.            
  43.             newButton.MouseButton1Click:Connect(function()
  44.                
  45.                 game.ReplicatedStorage.InventoryRE:FireServer("drop", item.Name)
  46.             end)
  47.        
  48.             newButton.Parent = script.Parent.InventoryScroller
  49.         end
  50.     end
  51.    
  52.     script.Parent.InventoryScroller.CanvasSize = UDim2.new(0, 0, 0, script.Parent.InventoryScroller.UIGridLayout.AbsoluteContentSize.Y)
  53. end
  54.  
  55. updateInv()
  56.  
  57. for i, item in pairs(inventoryFolder:GetChildren()) do
  58.     item.Changed:Connect(updateInv)
  59. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement