Hi, I created a crafting and Inventory system for my game, but I realised that when I craft something it deletes 2 of the needed item of the inventory in an indirect way, here is what I mean
this is the starter gui and where everything is located at
the inventory script deals with droping the items when clicked on the inventory gui and the local script is what deletes the item
this is the inventory and when you click on an item that you can pick up it goes here, and the box with the text “Text here” will be copied and specified with the item name that you picked up, like “Part” or “sword”
and this is the crafting screen it pops up when you press craft, it gives you the tool you select and deletes the item in your inventory
Video
here are the scripts
server script in serverscriptservice
local inventoryEvent = game.ReplicatedStorage.Events.InventoryEvent
game.Players.PlayerAdded:Connect(function(Player)
local Inventory = Instance.new("Folder", Player)
Inventory.Name = "Inventory"
Inventory.ChildAdded:Connect(function(Item)
inventoryEvent:FireClient(Player,Item.Name, true)
end)
inventoryEvent.OnServerEvent:Connect(function(Player, ItemName, Value)
if Value == false then
local SelectedItem = Player.Inventory:FindFirstChild(ItemName)
if SelectedItem:IsA("Modle") then
SelectedItem.Parent = game.Workspace
SelectedItem:SetPrimaryPartCFrame(Player.Character.HumanoidRootPart.CFrame + Vector3.new(0, 0, 2))
else
SelectedItem.Parent = game.Workspace
SelectedItem.CFrame = Player.Character.HumanoidRootPart.CFrame + Vector3.new(0, 0, 2)
end
end
end)
end)
Local script in the axe craft button
script.Parent.MouseButton1Click:Connect(function()
if game.Players.LocalPlayer.Inventory:FindFirstChild("Part") then
game.Players.LocalPlayer.Inventory:FindFirstChild("Part"):Destroy()
script.Parent.Parent.Parent.ItemFrame:FindFirstChild("Part"):Destroy()
local Backpack = game.Players.LocalPlayer.Backpack
local Tool = game.ReplicatedStorage.CraftableTools.Axe
wait(0.1)
if Tool then
Tool:clone().Parent = Backpack
end
print("Yes")
else
print("No")
end
end)
InventoryScript in mainframe
local InventoryEvent = game.ReplicatedStorage.Events.InventoryEvent
local ItemFrame = script.Parent:FindFirstChild("ItemFrame")
InventoryEvent.OnClientEvent:Connect(function(ItemName, Value)
if Value == true then
local ItemButton = ItemFrame:FindFirstChild("Sample"):Clone()
ItemButton.Visible = true
ItemButton.Name = ItemName
ItemButton.Text = ItemName
ItemButton.Parent = ItemFrame
ItemButton.MouseButton1Click:Connect(function()
ItemButton:Destroy()
InventoryEvent:FireServer(ItemName, false)
end)
end
end)
Basicly the problem is that when I craft a tool, it deletes it off my inventory, and when I drop the same item (another copy) It doesnt drop, and it does that to the ammount that I craft, like if I craft 5 and drop 5, the 5 of that item I drop wont drop but dissapear of my inventory
Anything will help