Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 4 years 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:

1script.Parent.blade.Touched:connect(function(p)
2 if script.Parent.CanDamage.Value == true then
3    script.Parent.CanDamage.Value = false
4    p.Parent.Humanoid:TakeDamage(15)
5  end
6end)

Local script:

01local CanAttack = true
02 
03script.Parent.Activated:connect(function()
04local Idle = script.Parent.Parent.Humanoid:LoadAnimation(script.Idle)
05local attack = script.Parent.Parent.Humanoid:LoadAnimation(script.Attack)
06 
07Idle:Play()
08end)
09 
10script.Parent.Activated:connect(function()
11local Idle = script.Parent.Parent.Humanoid:LoadAnimation(script.Idle)
12local attack = script.Parent.Parent.Humanoid:LoadAnimation(script.Attack)
13 
14if CanAttack == true then
15attack:Play()
View all 24 lines...

Can you help me?

0
Change the connect to Connect() because the connect is deprecated. Dovydas1118 1495 — 4y
0
Also you're not using remote events. Dovydas1118 1495 — 4y

1 answer

Log in to vote
0
Answered by 4 years 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

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

Answer this question