New: Nitro Boost our Discord server and receive full donation perks here on the website! Join the Scripting Helpers Discord Server to learn more! You can also Support on Patreon as always.
Ad
Still have questions? Join our Discord server and get real time help.
Log in to vote
0

how do i limit the number of touche events playing?

Asked by
Jumbuu 110
3 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 — 3y

1 answer

Log in to vote
0
Answered by
LostPast 253 Moderation Voter
3 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