Tool Equipped Detection Bugs

I am attempting to create a simple script that detects when you touch a part (SafeZone), and moves all tools you have into ServerStorage. When you leave the zone, you will get your tools back.

I was able to get the backpack to work fine. The tools get removed as intended, but I cannot get any tool equipped method to add an equipped tool to the table for deletion.

I have looked at multiple solutions on Dev, and a few other sources. I believe I don’t have my wording properly, as this should be a simple issue.

local ServerStorage = game:GetService("ServerStorage")
local border = script.Parent

border.Transparency = 1


border.Touched:Connect(function(hit)
	local player = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)

	local backpack = player:WaitForChild("Backpack")
	local tools = {}

	for _, tool in pairs(backpack:GetChildren()) do
		if tool:IsA("Tool") or tool.Parent == player.Character then
			table.insert(tools, tool)
		end
	end

	for _, tool in pairs(tools) do
		tool:Destroy()
		local newTool = tool:Clone()
		newTool.Parent = game.ServerStorage
	end
end)

This is the current version of the script. Any tool in the BackPack will be deleted for storing. However, if you have an equipped tool, it does not delete until you unequip it.

You’re only checking the player’s backpack for tools, not the character. That’s why it works when you unequip the tool, since it goes into your backpack. Add another for loop where you loop through the character to fix the issue:

for _, tool in pairs(backpack:GetChildren()) do
	if tool:IsA("Tool") then
		table.insert(tools, tool)
	end
end

for _, tool in pairs(player.Character:GetChildren()) do
	if tool:IsA("Tool") then
		table.insert(tools, tool)
	end
end
1 Like

btw, you are not using the ServerStorage variable

I see my issue now. In one of my attempts, I got close to this. Unfortunately my massive skills decided there was a better way to do it :sob: