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

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

Asked by 5 years ago

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

Log in to vote
0
Answered by
Troidit 253 Moderation Voter
5 years ago
Edited 5 years ago

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.

0
ah, ok. i'll be sure to keep this in mind in the future MrHMartra123 2 — 5y
0
Feel free to mark as answered on my post if I answered your question. Troidit 253 — 5y
0
I can't figure out how to mark it as answered. How can I do that? MrHMartra123 2 — 5y
0
There should be a button labeled "Accept Answer" with a checkmark bellow this comment box. Troidit 253 — 5y
Ad

Answer this question