Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

✓ Accepted answer
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!

2 comments

0

THANK YOU SO MUCH!!!!

0

No problem!

This discussion is preserved as it was. New answers, comments, and votes are closed.