How to detect if a tool is removed from player character and backpack properly?

So, I’ve been trying to make a better script to detects when a tool is removed from player completely(Backpack and Character).

If there’s any better method than this, please let me know. I just feel my script is messy and I’m pretty sure there’s a better way to do this…

  • The script:
local Player = script.Parent.Parent
local Backpack = script.Parent
local Character = game.Workspace:WaitForChild(Player.Name)
local Equipped = false


Backpack.ChildRemoved:Connect(function(tool)
	tool.Equipped:Connect(function()
		Equipped = true
		end)
		tool.Unequipped:Connect(function()
			Equipped = false
			end)
	if tool:FindFirstChild("Weapon") then
		wait(0.5)
		if tool.Parent ~= Character or tool.Parent ~= Backpack and Equipped == false then
		for i,v in pairs(Character:GetChildren()) do
			if v:IsA("Model") and v.Name == tool.Name then
				v:Destroy()
			end
		end
		end
	end
end)

Tool is in Backpack, there’s completely no issues with it I just wanna know if there’s any better methods to do this.

EDIT: In update of this situation, I found a better way to do this in my game when the player gets rid of a tool.

1 Like

Shouldn’t this be in #help-and-feedback:code-review

2 Likes

Oh, I’m sorry, I’m new to the forum and thought that this should be in scripting support. My bad.

2 Likes