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

How and when can you use debounce?

Asked by 5 years ago
Edited 5 years ago

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

Log in to vote
2
Answered by 5 years ago

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!

0
Very good and detailed explanation Tyler090130 619 — 5y
0
thanks man speedyfox66 237 — 5y
Ad

Answer this question