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.
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.