Hey, I was trying to do a tool that deals damage when touching a part while the tool is activated. My problem is that it deals damage (currently prints something) whenever the part is touched, regardless the weapon is activated or not. Here's the piece of the script. (It is a localscript inside a tool on player's backpack)
----//RightArm Damaging Function\\----
function RightDamage() --fired when tool is activated
if LastArm == "Left" then --checks if the moving arm is the right
char.RightHand.Touched:Connect(function(RDamager)
if not damagedebouce then
damagedebouce = true
print("Right Punch Hit") --I will change this with the damage
wait(0.6)
damagedebouce = false
end
end)
end
end
Here's the full scripts so you can see the local values and other things
----//Setting Arm Alternator\\----
LastArm = "Left"
----//Setting Debounces\\----
debounce = false
damagedebouce = false
----//Setting Local Values\\----
local Tool = script.Parent
local LeftPunch = Tool:WaitForChild("LeftPunch")
local RightPunch = Tool:WaitForChild("RightPunch")
local plr = game.Players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:wait()
while char.Parent == nil do
char.AncestryChanged:wait()
end
local humanoid = char:WaitForChild("Humanoid")
----//Loading Animations\\----
local AnimTrack = humanoid:LoadAnimation(RightPunch)
local AnimTrack2 = humanoid:LoadAnimation(LeftPunch)
----//Animate Function\\----
function Animator()
if not debounce then
debounce = true
if LastArm == "Left" then
AnimTrack:Play()
LastArm = "Right"
wait(0.5)
debounce = false
elseif LastArm == "Right" then
AnimTrack2:Play()
LastArm = "Left"
wait(0.5)
debounce = false
end
end
end
----//RightArm Damaging Function\\----
function RightDamage()
if LastArm == "Left" then
char.RightHand.Touched:Connect(function(RDamager)
if not damagedebouce then
damagedebouce = true
print("Right Punch Hit")
wait(0.6)
damagedebouce = false
end
end)
end
end
----//Calling Functions\\----
Tool.Activated:Connect(Animator)
Tool.Activated:Connect(RightDamage)
Thanks for your attention.

2 comments
You shouldn't have the Touched event inside the Activated event. If it is spammed, it will create tons of connections, and those things pile up you know.
how do I do it then?