Crafting Script Deletes 2 Items

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

No not really, the items that you pick up goes in a folder in the player character
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)

script in serverscriptservice

The part is being teleported because it checks if its in my inventory, but yeah it might be that its not getting deleted ill check

this part of code inside ServerScriptService has to be outside of game.Players.PlayerAdded
because every time player joins it connects another function to that event for example:

first player joins and then another one joins
now this event now has 2 connected functions
if one of them will fire the remote the function will be done twice

it says this
image

is it outside game.PLayers.PlayerAdded

image

Nope

It says that when I craft using a specific tem then drop a copy of the item ,like when I have 2 Parts in my inventory and use one to craft and drop the other one, the one I drop just dissapear to nowhere and says that in the output

Could be the reason?, I didn’t read the code enough. Thought that was an part.
image

this local script has to fire server and the server has to destroy the part and clone axe because everything done inside LocalScript is only visible to you

he meant that it is misspelled

no I dont think thats why, because thats an if statement, if its a modle then it will do that but if its a part it will do the rest after else

if SelectedItem:IsA("Modle") then 
			SelectedItem.Parent = game.Workspace
			SelectedItem:SetPrimaryPartCFrame(Player.Character.HumanoidRootPart.CFrame + Vector3.new(0, 0, 2))
		else  <---- if not modle 
			SelectedItem.Parent = game.Workspace
			SelectedItem.CFrame = Player.Character.HumanoidRootPart.CFrame + Vector3.new(0, 0, 2)
		end

You misspelled model is what he thought was the problem i didn`t get it too.

Also I think you may have not seen vlads script

Oh ok oof, no not because that , its trying to set locked parent

Sorry can you explain what that means? and also could we see your crafting script too I think it its self is the main problem.

Im not sure what that means myself but I did put the script, scroll to the post itself i put it under server script in serverscriptservice

game.Players.LocalPlayer.Inventory:FindFirstChild("Part"):Destroy()

So I see the inventory also has a copy when you make the axe how many are lost from the inventory?

what do you mean lost from the inventory?