How to get unequipped function to fire on tool destroy?

I have a custom equip system, as I’m not using the default backpack. However, destroying the tool results in the unequipped function inside it never firing?

--// Equip item
local function Equip(player, equipping, item)
	local Character = player.Character
	if not Character then return end
	
	local Humanoid = Character:FindFirstChildWhichIsA("Humanoid")
	if not Humanoid then return end
	
	local Tool = Character:FindFirstChildWhichIsA("Tool")
	if Tool then -- Clear any previous tools
		Tool:Destroy()
	end
	
	if not equipping then return end
	
	local StarterGear = player.StarterGear
	if not StarterGear then return end
	
	local ToolItem = StarterGear:FindFirstChild(item)
	if not ToolItem then return end
	
	local Clone = ToolItem:Clone()
	Clone.Parent = Character
end

EquipItem.OnServerEvent:Connect(Equip)

Tool script

local Tool = script.Parent

Tool.Equipped:Connect(function()
	print(1)
end)

Tool.Unequipped:Connect(function()
	print(2)
end)
1 Like

Are these in the same script? If so (sorry I’m on mobile),

The
Local tool variable should be set to the same variable as cloned for it to work multiple times, as your script only does this once.

You could create a variable

Local randomvar;

Set clone to randomvar in your equipped function:
Randomvar = clone

Then do

Local tool = random var

does not work when the tool is destroyed.

These are separate scripts.

more char

Then destroying the handle, and replacing the handle inside the tool rather than destroying the tool itself is your best bet here

1 Like