I'm currently making a sword right now, and everything works perfectly fine, except that if the blade of the sword touches an NPC, it does damage. I only want it to do damage when it is left-clicked with the mouse. Please help!
Local Script:
local CanAttack = true
local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local idle = char:WaitForChild("Humanoid"):LoadAnimation(script.idle)
local attack = char:WaitForChild("Humanoid"):LoadAnimation(script.attack)
script.Parent.Equipped:Connect(function(mouse)
idle:Play()
mouse.Button1Down:Connect(function()
if CanAttack then
idle:Stop()
attack:Play()
CanAttack = false
idle:Play()
wait(1)
attack:Stop()
CanAttack = true
script.Parent.CanDamage.Value = true
end
end)
end)
My other Local Script:
script.Parent.Equipped:Connect(function(mouse)
mouse.Button1Down:Connect(function()
script.Parent.blade.Touched:Connect(function(p)
if script.Parent.CanDamage.Value == true then
p.Parent.Humanoid:TakeDamage(20)
script.Parent.CanDamage.Value = false
wait(1)
script.Parent.CanDamage.Value = true
end
end)
end)
end)

1 comment
Just a tip. For something to take damage, make it a ServerScript so it's ServerSided and when they reach 0, they'll die. If it's a LocalScript, they won't die.