I have this knife/sword script that wont work properly. The aim of this script is to damage anyone who is hit by the knife. This works but after you damage the player you cannot damage them again? Here is my script
local Blade = script.Parent.Blade
local damage = script.Parent.DamagePerHit.Value
local Tool = script.Parent
script.Parent.Blade.Touched:connect(function(hit)
if script.Parent.CanHit.Value == true then
script.Parent.CanHit.Value = false
if hit.Parent:FindFirstChild("Humanoid") ~= nil then
hit.Parent.Humanoid:TakeDamage(script.Parent.DamagePerHit.Value)
script.Parent.Parent.Parent.leaderstats.Points.Value = script.Parent.Parent.Parent.leaderstats.Points.Value+script.Parent.DamagePerHit.Value
end
wait(2)
script.Parent.CanHit.Value = true
end
end)
As you can see it is programmed to take off their health whenever they touch the blade. But it only works once?
If anyone can give me a fix or even just an alternative that would be great!

5 comments
I don't see anything wrong about your script.
Any errors? Which script you used and where you put it?
Well maybe because you're using a denounce, but most debounces start with if false then true and then after the wait it becomes false again. You did the opposite
Sadmir, actually you can use both but making it true first is prefered among many people. However, for this problem at hand everything looks fine.
Unrelated to the problem, since you defined
Toolas script.Parent, use it...if script.Parent.CanHit.Value->if Tool.CanHit.Valueeasier to read, easier to understand, line 10 you would just use the player object instead of a million parents as well