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

Did I do Debounce correctly?

Asked by 9 years ago
function onTouched(hit)
    debounce = false
    local humanoid = hit.Parent:findFirstChild("Humanoid")
    debounce = true
    if (humanoid ~= nil) then
        humanoid.Health = humanoid.Health - 10
        wait(2)
        debounce = false
    end
end

script.Parent.Touched:connect(onTouched)

1 answer

Log in to vote
0
Answered by
Teeter11 281 Moderation Voter
9 years ago

debounce is so you will only press a button once instead of it getting called a bunch of times.

   debounce = false

function onTouched(hit)

if  debounce == false then
    local humanoid = hit.Parent:findFirstChild("Humanoid")
    debounce = true
    if (humanoid ~= nil) then
        humanoid.Health = humanoid.Health - 10
        wait(2)

    end
end
debounce = false
end

script.Parent.Touched:connect(onTouched)

0
Yes, I understand that. I know what debounce is. TheRings0fSaturn 28 — 9y
Ad

Answer this question