Delete Tool from Inventory when Delete Button is pressed?

Hi everyone I’m currently working on an Inventory System and my Part I’m working on now is how to delete a Tool from the Inventory so rn if I press on a Tool in my Inventory I can see the Name of the Tool,I can equip the Tool and I can press on an Delete yButton which leads me to a SureFrame that gives u the last Chance for not deleting/deleting the Tool here r some pics:
When I press on a Tool:


When I press on the Delete Button:

So this is how it works and when I press on the Cancel Button the Frame sets automatically Visible to false now what I need to function is that when I press on the “Yes” Button which should be the Parent of the Local Script(I can tell the exact position of the Button if u want) the Tool should automatically get deleted I think everyone knows what I mean now I got a Script here which is located in the ServerScriptService he should have all elements u guys need I think I got another LocalScript in the InventoryFrame but he isn’t useful I believe now the Script:

local inventoryEvent = game.ReplicatedStorage.Remotes.InventoryEvent

game.Players.PlayerAdded:Connect(function(player)
	
	local inventory = player:WaitForChild("Inventory")
	
	local inventoryFrame = player.PlayerGui:WaitForChild("InventoryGui").InventoryFrame.ItemsFrame:GetChildren()
	
	inventory.ChildAdded:Connect(function(Item)
		inventoryEvent:FireClient(player, Item.Name, true)
	end)
end)

inventoryEvent.OnServerEvent:Connect(function(player, ItemName, Value, button)
	
	 if Value == false then
			local SelectedItem = player.Inventory:FindFirstChild(ItemName)
			local backpack = player.Backpack:GetChildren()
			local stuff = player.Character:GetChildren()
			
			if #backpack == 0 and not player.Character:FindFirstChildWhichIsA("Tool") then
				button.Text = "Unequip"
				button.BackgroundColor3 = Color3.new(255,0,0)
				SelectedItem:Clone().Parent = player.Backpack
			else
				for i,v in ipairs(backpack) do
					button.Text = "Equip"
					button.BackgroundColor3 = Color3.new(0,255,0)
					v:Destroy()
				end
				for i, v in ipairs(stuff) do
					if v:IsA("Tool") then
						button.Text = "Equip"
						button.BackgroundColor3 = Color3.new(0,255,0)
						v:Destroy()
					end
				end
			end
	 end
end)
1 Like

You have to destroy the tool on the server using a remote event.

1 Like

To delete a tool from the inventory when the “Yes” button is pressed, you can use a LocalScript to handle the button click and a RemoteEvent to communicate with the server for secure removal.

First, attach a LocalScript to the “Yes” button. This script will listen for the click event and then fire a RemoteEvent to the server with the tool name to be deleted.

Next, update your server script to handle the “Delete” request. The server script should listen for the event and then find and destroy the specified tool in the player’s inventory.

This method ensures that the deletion action is securely handled by the server, preventing unauthorized item deletions by clients.

1 Like