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.