Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local rs = game:GetService("ReplicatedStorage")
- local player1
- local Max_stacked_items = {
- Consumable = 4,
- Resource = 4,
- Weapon = 1,
- Armor = 1,
- Artifact = 1,
- StackId = 0
- }
- local fullystacked = false
- local stacked = false
- local counted
- game.Players.PlayerAdded:Connect(function(player)
- player1 = player
- player.CharacterAdded:Connect(function()
- local inv = Instance.new("Folder")
- inv.Name = "Inventory"
- inv.Parent = player
- player.Character.ChildAdded:Connect(function(child)
- end)
- player.Backpack.ChildAdded:Connect(function(child)
- wait(.2)
- local stacked = nil
- for i, v in player.Inventory:GetChildren()do -------------Check if the item is already in the inventory
- if v:IsA("Folder") and v.Name == child.Name then
- stacked = true
- elseif v:IsA("Folder") and v.Name ~= child.Name then
- stacked = false
- end
- end
- -------------------------------------------------------------------------
- if stacked == true and child.Stackable.Value == true then ---------------if the item is in the inventory then it will stack
- for i , v in player.Inventory:GetDescendants()do
- wait()
- if v:IsA("IntValue") and v.Name == child.Name then
- if v.Name == child.Name and v.Value < Max_stacked_items.Consumable then
- v.Value += 1
- elseif v.Name == child.Name and v.Value == Max_stacked_items.Consumable then
- counted = v.Parent
- print(counted)
- return
- end
- end
- end
- local table1 = {}
- for i2, stack in table1 do
- wait()
- print("ran1")
- if stack.StackId ~= counted.Parent.StackId then
- print("ran2")
- table.insert(table1, counted)
- local stack = Instance.new("Folder")
- stack.Name = child.Name
- stack.Parent = player.Inventory
- local stackid = Instance.new("IntValue")
- stackid.Name = "StackId"
- stackid.Value = Max_stacked_items.StackId + 1
- stackid.Parent = stack
- local new = Instance.new("IntValue")
- new.Name = child.Name
- new.Parent = stack
- new.Value = 1
- print("Ran")
- return
- end
- end
- ------------------------------------------------------------
- elseif not stacked and child.Stackable.Value == true then -----if the item is not in the inventory but it is stackable
- local stack = Instance.new("Folder")
- stack.Name = child.Name
- stack.Parent = player.Inventory
- local stackid = Instance.new("IntValue")
- stackid.Name = "StackId"
- Max_stacked_items.StackId += 1
- stackid.Value = Max_stacked_items.StackId
- stackid.Parent = stack
- local new = Instance.new("IntValue")
- new.Name = child.Name
- new.Parent = stack
- new.Value = 1
- stacked = true
- return--------------------------------------------------------------------
- elseif not stacked and child.Stackable.Value == false then ----if the item is not in the inventory and it is not stackable
- local new = Instance.new("IntValue")
- new.Name = child.Name
- new.Parent = player.Inventory
- new.Value = 1
- return
- end----------------------------------------------------
- end)
- player.Backpack.ChildRemoved:Connect(function(child)
- end)
- player.Character.ChildRemoved:Connect(function(child)
- end)
- end)
- end)
Advertisement
Add Comment
Please, Sign In to add comment