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

Script that takes deducts players health only works once?

Asked by
iladoga 129
5 years ago

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!

0
I don't see anything wrong about your script. cherrythetree 130 — 5y
0
Any errors? Which script you used and where you put it? HeyItzDanniee 252 — 5y
0
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 ScrubSadmir 200 — 5y
0
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. TheLightningRises 56 — 5y
0
Unrelated to the problem, since you defined `Tool` as script.Parent, use it...`if script.Parent.CanHit.Value` -> `if Tool.CanHit.Value` easier to read, easier to understand, line 10 you would just use the player object instead of a million parents as well Vulkarin 581 — 5y

Answer this question