A script inside a part that is supposed to remove a specific tool from the player's inventory.
The script works great for 1 Variable, but it stops working whenever I try to add another Tool's name to the table.
Working Example - local ToolName = "Tool"
Not Working Example - local ToolName = { "Tool", "Tool2" }
local ToolName = { "Tool", "Tool2" }
-- local ToolName = "Tool"
function RemoveWeapons(parent)
local weapons = parent:GetChildren()
for i = 1,#weapons do
if (weapons[i].className == "Tool") and (weapons[i].name == ToolName) then <-- Error
weapons[i]:remove()
end
end
end
function onTouched(hit)
local player = game.Players:FindFirstChild(hit.Parent.Name)
local backpack = player.Backpack
if (table.maxn(backpack:GetChildren()) > 0) then
RemoveWeapons(backpack)
end
RemoveWeapons(player.Character)
end
script.Parent.Touched:connect(onTouched)

1 comment
Your script had a small error in it, fixed it, works great, thanks!