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

Why does this script stop working when i add a debounce to it?

Works normally, but I want the script to have a debounce. Whenever i try to add a debounce though, it just doesn't run.

script.Parent.Touched:Connect(function(throw)
    local debounce = false
    if debounce then
	    debounce = true
	    script.Parent.Anchored = false
	    script.Parent.Velocity = script.Parent.Velocity + Vector3.new(-100, 100, -100)
	    wait(0.25)
	    script.Parent.Parent.Parent.leaves.oddleaves.WeldConstraint.Enabled = false
	    local explosion = Instance.new("Explosion", workspace)
	    explosion.Position = script.Parent.Parent.Parent.leaves.oddleaves.Position
	    wait(0.45)
	    debounce = false
	end
end)

Whenever I try to touch the part which should start this script, nothing happens. Wiki hasn't exactly been helping very much, either.

1 answer

✓ Accepted answer

Make sure on line three you check that it's false, not true.

script.Parent.Touched:Connect(function(throw)
    local debounce = false
    if debounce then -- "If true then"

SO you would want it like this:

script.Parent.Touched:Connect(function(throw)
    local debounce = false
    if not debounce then -- if not true (aka false)

Because the decision structure will only carry through if the condition is true, even though you set it false before hand.

4 comments

0

ah, ok. i'll be sure to keep this in mind in the future

0

Feel free to mark as answered on my post if I answered your question.

0

I can't figure out how to mark it as answered. How can I do that?

0

There should be a button labeled "Accept Answer" with a checkmark bellow this comment box.

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