Greetings!
I have been working on a tool with attack, run, idle animation and I have little problem with Touched event. The problem is when I click, animations plays and then if I come next to goblin and if my "Blade" in tool touches the goblin's Humanoid, goblin will lose damage. I don't want that. I want when I click somewhere and come with my "Blade" next to goblin he won't take damage. Only when I activate the tool and my "Blade" touches him in same time he will take damage. I hope you understood. Here is the script I have problem with:
local CanAttack = true script.Parent.Activated:Connect(function() if CanAttack == true then local tool = script.Parent.Parent local idle2 = script.Parent.Parent.Humanoid:LoadAnimation(script.Parent.LocalScript.Idle2) local attack = script.Parent.Parent.Humanoid:LoadAnimation(script.Parent.LocalScript.Attack) local run = script.Parent.Parent.Humanoid:LoadAnimation(script.Parent.LocalScript.Run) local idled = script.Parent.Parent.Humanoid:LoadAnimation(script.Parent.LocalScript.IdleDefault) local Humanoid = script.Parent.Parent.Humanoid idle2:Stop() CanAttack = false attack:Play() script.Parent.Blade.Touched:Connect(function(hit) if hit.Parent.Humanoid and script.Parent.CanDamage.Value == true then hit.Parent.Humanoid:TakeDamage(30) script.Parent.CanDamage.Value = false end end) if Humanoid.MoveDirection.Magnitude > 0 then run:Play() else idle2:Stop() run:Stop() print("Stop running -- line 64") end CanAttack = true script.Parent.CanDamage.Value = true end end)