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

how do i limit the number of touche events playing?

Asked by
Jumbuu 110
8 years ago
script.Parent.Blade.Touched:connect(function(hit)
    if equipped and humanoid  and humanoid.Health >=0 then
    print(hit.Parent.Name)
    target = hit.Parent:FindFirstChild'Humanoid'
        if target and target.Health >= 0 then
            print(hit.Parent.Name)
            target:TakeDamage(damage.Value)
            end
    end
end)

the code fires like 5 touched events when ever it hits something with a humanoid

0
how do i limit the number of touched events firing? Jumbuu 110 — 8y

1 answer

Log in to vote
0
Answered by
LostPast 253 Moderation Voter
8 years ago
local deb = true

script.Parent.Blade.Touched:connect(function(hit)
    if equipped and humanoid  and humanoid.Health >=0 and deb == true then
    deb = false
    print(hit.Parent.Name)
    target = hit.Parent:FindFirstChild'Humanoid'
        if target and target.Health >= 0 then
            print(hit.Parent.Name)
            target:TakeDamage(damage.Value)
            end
wait()
    deb = true
    end
end)

Creating a debounce makes it so that the item can't be touched again for a certain amount of time.

Ad

Answer this question