I made a custom inventory system and its really buggy
Video of the problem:
Server Script:
if item.Parent == plr:FindFirstChild("StoredItems") then
if #plr:FindFirstChild("HotbarItems"):GetChildren() < 10 then
if #plr:FindFirstChild("HotbarItems"):GetChildren() > 0 then
for i, v in pairs(plr:FindFirstChild("HotbarItems"):GetChildren()) do
if v.Name == item.Name then
if v.Quantity.Value + item.Quantity.Value <= v.MaxStackSize.Value then
v.Quantity.Value += item.Quantity.Value
item:Destroy()
else
item.Parent = plr:FindFirstChild("HotbarItems")
end
end
end
else
item.Parent = plr:FindFirstChild("HotbarItems")
end
end
end
if item.Parent == plr:FindFirstChild("HotbarItems") then
if #plr:FindFirstChild("StoredItems"):GetChildren() < plr:FindFirstChild("InventoryStorage").Value then
if #plr:FindFirstChild("StoredItems"):GetChildren() > 0 then
for i, v in pairs(plr:FindFirstChild("StoredItems"):GetChildren()) do
if v.Name == item.Name then
if v.Quantity.Value + item.Quantity.Value <= v.MaxStackSize.Value then
v.Quantity.Value += item.Quantity.Value
item:Destroy()
else
item.Parent = plr:FindFirstChild("StoredItems")
end
end
end
else
item.Parent = plr:FindFirstChild("StoredItems")
end
end
end
end)
Local Script:
local rs = game:GetService("ReplicatedStorage")
local events = rs.Events
local function RefreshInventory()
for i, v in pairs(script.Parent.InventoryBG.InventoryHolder:GetChildren()) do
if v:IsA("ImageButton") then
v:Destroy()
end
end
for i, v in pairs(player:FindFirstChild("StoredItems"):GetChildren()) do
local slot = script.Parent.InventoryBG.SampleSlot:Clone()
slot.Parent = script.Parent.InventoryBG.InventoryHolder
slot.Name = v.Name
slot.ItemQuantity.Text = tostring(v.Quantity.Value)
slot.Visible = true
slot.MouseButton1Click:Connect(function()
events.TransferItem:FireServer(v)
wait()
RefreshInventory()
end)
end
end
wait()
RefreshInventory()
script.Parent.Parent:WaitForChild("MainGui").ToggleInventoryButton.MouseButton1Click:Connect(function()
RefreshInventory()
script.Parent.Enabled = not script.Parent.Enabled
end)
player:FindFirstChild("HotbarItems").ChildAdded:Connect(function()
RefreshInventory()
end)
player:FindFirstChild("StoredItems").ChildAdded:Connect(function()
RefreshInventory()
end)
while wait() do
if player:WaitForChild("StoredItems") then
script.Parent.InventoryBG.InventoryHolder.CanvasSize = UDim2.new(0,0,0,script.Parent.InventoryBG.InventoryHolder.UIGridLayout.AbsoluteContentSize.Y + 10)
end
end