EliteGod532111

Untitled

Jul 12th, 2025
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.58 KB | None | 0 0
  1.  
  2. local rs = game:GetService("ReplicatedStorage")
  3.  
  4. local player1
  5.  
  6.  
  7.  
  8.  
  9. local Max_stacked_items = {
  10.     Consumable = 4,
  11.     Resource = 4,
  12.     Weapon = 1,
  13.     Armor = 1,
  14.     Artifact = 1,
  15.     StackId = 0
  16. }
  17.  
  18. local fullystacked = false
  19.  
  20.  
  21.  
  22. local stacked = false
  23.  
  24. local counted
  25.  
  26.  
  27.  
  28. game.Players.PlayerAdded:Connect(function(player)
  29.     player1 = player
  30.     player.CharacterAdded:Connect(function()
  31.         local inv = Instance.new("Folder")
  32.         inv.Name = "Inventory"
  33.         inv.Parent = player
  34.  
  35.  
  36.  
  37.  
  38.  
  39.  
  40.  
  41.  
  42.  
  43.  
  44.  
  45.  
  46.  
  47.  
  48.     player.Character.ChildAdded:Connect(function(child)
  49.     end)
  50.  
  51.  
  52.  
  53.    
  54.     player.Backpack.ChildAdded:Connect(function(child)
  55.         wait(.2)
  56.                 local stacked = nil
  57.                
  58.                
  59.  
  60.                 for i, v in player.Inventory:GetChildren()do -------------Check if the item is already in the inventory
  61.                     if v:IsA("Folder") and v.Name == child.Name then
  62.                         stacked = true
  63.                     elseif v:IsA("Folder") and v.Name ~= child.Name then
  64.                         stacked = false
  65.                     end
  66.                 end
  67.                 -------------------------------------------------------------------------
  68.  
  69.  
  70.  
  71.  
  72.  
  73.                 if stacked == true and child.Stackable.Value == true then ---------------if the item is in the inventory then it will stack
  74.            
  75.                 for i , v in player.Inventory:GetDescendants()do
  76.                     wait()
  77.                
  78.                     if v:IsA("IntValue") and v.Name == child.Name then
  79.                        
  80.                         if v.Name == child.Name and v.Value < Max_stacked_items.Consumable then
  81.                            
  82.                             v.Value += 1
  83.                         elseif v.Name == child.Name and v.Value == Max_stacked_items.Consumable then
  84.                             counted = v.Parent
  85.                             print(counted)
  86.                             return
  87.                                
  88.                         end
  89.                     end
  90.                 end
  91.                
  92.                        
  93.                        
  94.                             local table1 = {}
  95.  
  96.                             for i2, stack in table1 do
  97.                                 wait()
  98.                                 print("ran1")
  99.  
  100.                                 if stack.StackId ~= counted.Parent.StackId then
  101.                                     print("ran2")
  102.                                     table.insert(table1, counted)
  103.  
  104.  
  105.                                     local stack = Instance.new("Folder")
  106.                                     stack.Name = child.Name
  107.                                     stack.Parent = player.Inventory
  108.  
  109.                                     local stackid = Instance.new("IntValue")
  110.                                     stackid.Name = "StackId"
  111.                                     stackid.Value = Max_stacked_items.StackId + 1
  112.                                     stackid.Parent = stack
  113.  
  114.                                     local new = Instance.new("IntValue")
  115.                                     new.Name = child.Name
  116.                                     new.Parent = stack
  117.                                     new.Value = 1
  118.                                     print("Ran")
  119.                                     return
  120.                                 end
  121.                             end
  122.                            
  123.                            
  124.                        
  125.            
  126.                     ------------------------------------------------------------
  127.  
  128.  
  129.  
  130.                 elseif not stacked and child.Stackable.Value == true then  -----if the item is not in the inventory but it is stackable
  131.                     local stack = Instance.new("Folder")
  132.                     stack.Name = child.Name
  133.                     stack.Parent = player.Inventory
  134.  
  135.                     local stackid = Instance.new("IntValue")
  136.                     stackid.Name = "StackId"
  137.                     Max_stacked_items.StackId += 1
  138.                     stackid.Value = Max_stacked_items.StackId
  139.                     stackid.Parent = stack
  140.  
  141.                     local new = Instance.new("IntValue")
  142.                     new.Name = child.Name
  143.                     new.Parent = stack
  144.                     new.Value = 1
  145.                     stacked = true
  146.                     return--------------------------------------------------------------------
  147.  
  148.  
  149.  
  150.                 elseif not stacked and child.Stackable.Value == false then ----if the item is not in the inventory and it is not stackable
  151.                     local new = Instance.new("IntValue")
  152.                     new.Name = child.Name
  153.                     new.Parent = player.Inventory
  154.                     new.Value = 1
  155.                     return
  156.                 end----------------------------------------------------
  157.            
  158.  
  159.  
  160.  
  161.  
  162.     end)
  163.    
  164.    
  165.    
  166.     player.Backpack.ChildRemoved:Connect(function(child)
  167.        
  168.     end)
  169.    
  170.    
  171.     player.Character.ChildRemoved:Connect(function(child)
  172.        
  173.     end)
  174.    
  175.     end)
  176. end)
  177.  
  178.  
Advertisement
Add Comment
Please, Sign In to add comment