Hello, devs!
So title might be hard to understand, but I will explain everything right now. So I was making a sword tool that deals damage when you touch dummy and you activate tool (Mouse Click). My problem is if that if your tool will touch dummy and you will walk away and click your mouse, dummy will still get damaged. I also made string value that stores your name when you equip your tool and it works.
CODE:
script.Parent.Parent.Equipped:Connect(function()
local player = script.Parent.Parent.Parent
local debounce = false
script.Parent.Parent.Owner.Value = player.Name
script.Parent.Touched:Connect(function(hit)
script.Parent.Parent.Activated:Connect(function()
if hit.Name ~= script.Parent.Parent.Owner.Value then
if hit.Parent:FindFirstChild("Humanoid") then
if debounce == false then
debounce = true
hit.Parent:FindFirstChild("Humanoid").Health = hit.Parent:FindFirstChild("Humanoid").Health - 50
wait(1)
debounce = false
end
end
end
end)
end)
end)
ERRORS:
No errors
DETAILS:
Sword Tool located in workspace, script located in part that is located in tool (everything is welded), owner name string value located in tool.

3 comments
I recommend not using the touched event. You should use magnitude with the Dot product.
What do you mean? I have no idea how to use magnitude...
Magnitude can detect how far an object is from another object, I recommend checking this out: https://scriptinghelpers.org/questions/14617/how-do-i-use-magnitude