What's the best way to check whether a tool that the humanoid equipped is a weapon?

Hi developers! I was trying out new code earlier, and encountered a problem:

How can I check whether a humanoid has equipped a weapon that’s in the weapon table?

I know the weapon table part, since it’s just

table.find(...)

but I don’t know how to connect that to the equip event so I can check it.

The full thing should be like this:
If humanoid equips a tool, the script checks whether the tool name is in the table.

Help is appreciated, thanks!

local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()

local WeaponTable = {"Sword"}

Character.ChildAdded:Connect(function(Child)
   if Child:IsA("Tool") and table.find(WeaponTable, Child.Name) then
print('Weapon!')
end
end)
1 Like