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

Why are my multiple debounces not working?

Asked by 5 years ago

So I'm making a blooming garden, which the person themselves grows just by stepping on it.

If they step on the soil, the seed will become transparent, and a sprout will bloom in place. If a person steps on the soil again, a flower will bloom in place.

This is my script so far:

debounce = false

script.Parent.Soil.Touched:connect(function()

    if not debounce then 

        debounce = true

        for i = 0, 1, 0.1 do
        script.Parent.Seed.Transparency = i
        wait (0.1)
    end
    wait(10)
    debounce = false 

    end


debounce = true

if debounce then 
     for i = 1, 0, -0.1 do
        script.Parent.Sprout.Transparency = i
        wait (0.1)

    end
        wait(5)


end

end)




The problem, the seed "dissolves" once. But the sprout, keeps appearing to flash as a result of it being touched too many times. Hence, I thought a debounce would be a good idea to fix this.

In other words, the debounce worked for the seed but not for the sprout.

1 answer

Log in to vote
1
Answered by
Shawnyg 4330 Trusted Badge of Merit Snack Break Moderation Voter Community Moderator
5 years ago

The reason it will not work for the sprout is due to the order of your if statements. The second one will always work if the first one does not, and vice versa. I'd recommend creating a seperate debounce variable for the sprout (note: It doesn't need to be named "debounce", it could be any value) and properly setting it up.

0
Thank you so much! My first scripting project is going well! Note to others who have the same problem as me- What I did, was make the second debounce variable and named it "rebounce" or something else. crystalclay 70 — 5y
Ad

Answer this question