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

my function only works once for my touch function, what am I doing wrong?

Asked by
Noxnuo 11
4 years ago

So Im building and when I use my touch function in only works once then it stops. Is there something Im doing wrong?

My sword script for touch and damage:

script.Parent.DamagePart.Touched:Connect(function(p)
    if script.Parent.CanDamage.Value == true then
    script.Parent.CanDamage.Value = false
    p.Parent.Humanoid:TakeDamage(20)
    end
end)

1 answer

Log in to vote
0
Answered by 4 years ago
script.Parent.DamagePart.Touched:Connect(function(p)
    if script.Parent.CanDamage.Value == true then
    script.Parent.CanDamage.Value = false
    p.Parent.Humanoid:TakeDamage(20)
    script.Parent.CanDamage.Value = true
    end
end)

You never set the CanDamage value back to true, so the script doesn't get the heads up to run again. You can add a wait if you want to so they don't get damaged as rapidly if you want. This will set it back to true right after the character takes the 20 damage.

Hope this helps!

0
THANK YOU SO MUCH!!!! Noxnuo 11 — 4y
0
No problem! DarkDanny04 407 — 4y
Ad

Answer this question