Help with Inventory System

I’ve been recently coding in a custom inventory system for a passion project however, I’ve ran into this issue many times. I am unsure on how to check if the item associated with the equipped tool is removed or not and if the item is removed, it should remove the equipped tool. I was hoping someone could help me figure out how to go bout this. Any help would greatly be appreciated!
I can provide scripts, and locations of said scripts if needed!

How would it be removed, and where would it be removed? If the item is in the character then you can use child.Destroying to detect when the specific part is being destroyed. Sample:

local player = game.Players.LocalPlayer
for i,child in pairs(player.Character:GetChildren()) do
   child.Destroying:Connect(function()
      local toolname = child:GetAttribute('AssociatedTool') 
      if toolname and player.Backpack:FindFirstChild(toolname)
         player.Backpack[toolname]:Destroy()
      end
   end)
end
1 Like