Ok, so I have an inventory system, it pratically works fine, but there is a bug that I found out when I tested it with my friends that when you drop the item there is a chance it duplicates once or more, I have no idea how that happens cause that bug didn’t happen for me but for my friend and it almost always happened when he tried to drop all items in the inventory very fast (Little side note: The ping of my friend was relatively high).
-- Local script:
local player = game.Players.LocalPlayer
local RS = game:GetService("ReplicatedStorage")
local InventoryPlayer = player:WaitForChild("Inventory")
local template = game:GetService("ReplicatedStorage"):WaitForChild("Template")
local RF = RS:WaitForChild("RemoveItemFromInventory")
--// Events
local function handleAddition(child)
if child then
local templateClone = template:Clone()
templateClone.Parent = player.PlayerGui.InventoryGUI.Frame
templateClone.Name = child.Name
templateClone.TextLabel.Text = child.Name
templateClone.TextButton.Text = child.Name.." x"..child.Value
child:GetPropertyChangedSignal("Value"):Connect(function()
templateClone.TextButton.Text = child.Name.." x"..child.Value
end)
templateClone.TextButton.MouseButton1Click:Connect(function()
local nameOfItem = templateClone.Name
local item = game:GetService("ReplicatedStorage").Items:FindFirstChild(nameOfItem)
if item then
local result = RF:InvokeServer(item)
if result == "removeGUI" then
templateClone:Destroy()
end
end
end)
end
end
InventoryPlayer.ChildAdded:Connect(handleAddition)
-- Normal script:
local RS = game:GetService("ReplicatedStorage")
local RF = RS:WaitForChild("RemoveItemFromInventory")
local function removeItemFromInventory(player, item)
local cloneItem = item:Clone()
cloneItem.CFrame = player.Character.HumanoidRootPart.CFrame * CFrame.new(0, 0, -1)
cloneItem.Parent = workspace
if player.Inventory:FindFirstChild(item.Name) then
if player.Inventory[item.Name].Value > 1 then
player.Inventory[item.Name].Value = player.Inventory[item.Name].Value - 1
else
player.Inventory[item.Name]:Destroy()
return "removeGUI"
end
end
end
RF.OnServerInvoke = removeItemFromInventory```