I'm trying to make a good punch tool but even though it is unequipped and I am not clicking it still does damage to the enemy NPCs. How can I fix this? (script) I've already tried things like: -tool.Activated -debounce
Here's the script:
local tool = script.Parent
local hitsound = tool:WaitForChild("Hit")
local canattack = tool:WaitForChild("CanAttack")
local plr = tool.Parent.Parent
local char = plr.Character or plr.CharacterAdded:wait()
local larm = char:WaitForChild("LeftHand")
local rarm = char:WaitForChild("RightHand")
larm.Touched:Connect(function(hit)
local hum = hit.Parent:FindFirstChild("Humanoid")
if canattack.Value == false then
if hum then
canattack.Value = true
hitsound:Play()
hum:TakeDamage(10)
wait(.5)
canattack.Value = false
end
end
end)
rarm.Touched:Connect(function(hit)
local hum = hit.Parent:FindFirstChild("Humanoid")
if canattack.Value == false then
if hum then
canattack.Value = true
hitsound:Play()
hum:TakeDamage(10)
wait(.5)
canattack.Value = false
end
end
end)

2 comments
This would be your best bet. And for future reference, the "touched" event runs every time you touch something so you would need to somehow verify it is in equipped before taking damage.
Thanks! It works