Ad
Still have questions? Join our Discord server and get real time help.
Log in to vote
0

Help! I Have a problem! My sword only deals damage once. What happened?

Asked by 1 month ago

Ok, So. My sword only does damage once, When I swing it again, It doesn't do any damage any more. Here is my script. Script:

script.Parent.blade.Touched:connect(function(p)
 if script.Parent.CanDamage.Value == true then
    script.Parent.CanDamage.Value = false
    p.Parent.Humanoid:TakeDamage(15)
  end
end)

Local script:

local CanAttack = true

script.Parent.Activated:connect(function()
local Idle = script.Parent.Parent.Humanoid:LoadAnimation(script.Idle)
local attack = script.Parent.Parent.Humanoid:LoadAnimation(script.Attack)

Idle:Play()
end)

script.Parent.Activated:connect(function()
local Idle = script.Parent.Parent.Humanoid:LoadAnimation(script.Idle)
local attack = script.Parent.Parent.Humanoid:LoadAnimation(script.Attack)

if CanAttack == true then
attack:Play()
Idle:Stop()
CanAttack = false
wait(2)
attack:Stop()
Idle:Play()
CanAttack = true
script.Parent.CanDamage.Value = true
end
end)

Can you help me?

0
Change the connect to Connect() because the connect is deprecated. Dovydas1118 795 — 1mo
0
Also you're not using remote events. Dovydas1118 795 — 1mo

1 answer

Log in to vote
0
Answered by 1 month ago

The issue is you never set the script.Parent.CanDamage.Value back to true so the if statement will allways be false, here is the way you can fix it

script.Parent.blade.Touched:connect(function(p)
 if script.Parent.CanDamage.Value == true then
script.Parent.CanDamage.Value = false
p.Parent.Humanoid:TakeDamage(15)
wait(0.5) --Time between attacks
script.Parent.CanDamage.Value = true
end
end)
0
Thanks, Gooncreeper! Superboybull2 2 — 1mo
Ad

Answer this question