I wrote this server script for Catalog Heaven which attempts to destroy tools when the handle is destroyed. I just noticed this error in the developer console (occurs rarely):
tr1::bad_weak_ptr
Script 'Players.questionabletello.Backpack.HandleRemovalDetector', Line 11
Stack End
Am I doing something horribly wrong here to cause this error? Here’s the code:
local player = script.Parent.Parent
local character = player.Character
if not character or not character.Parent then
character = player.CharacterAdded:wait()
end
-- if a tool's handle is removed from the tool, then nuke the tool
character.DescendantRemoving:connect(function(descendant)
if descendant.Name == "Handle" then
local tool = descendant.Parent and descendant.Parent:IsA("Tool") and descendant.Parent --> tr1::bad_weak_ptr
if tool then
wait(0)
if not descendant.Parent then
print("Removing tool without handle")
pcall(function() tool:Destroy() end)
end
end
end
end)