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

How and when can you use debounce?

i've just wondered, is it like a delay type of thing or just something you put? can someone let me know how it works and when I should use it

edit: sorry for not being specific enough ima edit again soon

1 answer

✓ Accepted answer

A debouce is something you add in a script or a local script so that when the function is activated, it will not activate again until it has finished to run. Example:

local debounce = false

game.Workspace.Part.Touched:Connect(function(hit)
	if debounce == false then
		debounce = true
		--add everything you want (let's call this x)
	end
	debounce = false
end)

So when a player touches a part, that function will run EVERY mili seconds, but you want that the function finishes before running the function again. So I added an if statement that detects if the debounce = true. If the debounce is true, it will run the lines inside (so x). However, if it's false, it will not run the line inside UNTIL the debounce = false again (line 8). You may ask why I put the debounce = false at line 8. Because if the if statement at line 4 doesn't run, it will stop the function, INCLUDING line 8.

Debounces can also be used in those "while wait() do".

Debounces can also be named with other names, such as "loading" or "waiting"

Hope this helped!

2 comments

0

Very good and detailed explanation

0

thanks man

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