Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Did I do Debounce correctly?

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

✓ Accepted answer

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)

1 comment

0

Yes, I understand that. I know what debounce is.

This discussion is preserved as it was. New answers, comments, and votes are closed.