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

Why are my multiple debounces not working?

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

✓ Accepted answer

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.

1 comment

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.

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