Instance.Destroying isn't firing inside tool

I want to be able to check if a tool has been destroyed with a script that is inside the tool but it never fires. I have tried to use both server and client scripts but they don’t work. It only works if a script is parented out of the tool. Is there a way of making this work?

image

local tool = script.Parent

tool.Destroying:Connect(function()
	print("server")
end)
game.ReplicatedStorage.DestroyTool.OnServerEvent:Connect(function(player)
	local character = player.Character
	local tool = character:FindFirstChildWhichIsA("Tool")
	
	if tool then
		tool:Destroy()
	end
end)

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)
		character.ChildAdded:Connect(function(child)
			if child:IsA("Tool") then
				child.Destroying:Connect(function()
					print("test") -- only works
				end)
			end
		end)
	end)
end)

Here is the place file:
Destroying event test.rbxl (59.8 KB)

1 Like

You can fire an event to a different script outside of the tool before destroying it.
Essentially your script waits for the tool to get destroyed, but the script gets destroyed with the tool so it never has time to do anything

3 Likes

But doesn’t the Destroying event fires before actually destroying the tool?

ngl try script.Destroying instead of tool.Destroying since it’s under tool anyway and should get destroyed at the same time

That doesn’t work either. The tool would be the one getting destroyed so I don’t think that would work.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.