I want my sword to deal damage upon it is activated, instead I have a sword that just deals damage if something touches it, any ideas how to make this.
(I have 2 scripts, a local script and a script inside the tool)
script
local tool = script.Parent
local canAttack = true
local damage = math.floor(math.random(4,8))
local function onTouch(hit)
local humanOther = hit.Parent:FindFirstChild("Humanoid")
if not humanOther then return end
if not canAttack then return end
if humanOther.Parent == tool then return end
humanOther:TakeDamage(damage)
canAttack = false
wait(0.3)
canAttack = true
tool.Handle.Touched:Connect(hit)
end
Local script
wait()
local player = game:GetService("Players").LocalPlayer
local character = player.Character
local animation1 = script.Parent:FindFirstChild("Attack 1")
local swingAnimation1 = character.Humanoid:LoadAnimation(animation1)
local animation2 = script.Parent:FindFirstChild("Attack 2")
local swingAnimation2 = character.Humanoid:LoadAnimation(animation2)
local canSwing = true
local debounce = 0.9
local doneAttack1 = false
script.Parent.Activated:Connect(function()
if canSwing then
if doneAttack1 == false then
canSwing = false
swingAnimation1:Play()
wait(debounce)
canSwing = true
elseif doneAttack1 then
canSwing = false
swingAnimation2:Play()
wait(debounce)
canSwing = true
end
end
end)