Is it better to use Debounce or :Wait()

for example,


local Debounce = true

button.MouseEnter:Connect(function()
 if Debounce then
  --whatever
 end
end)

or


while wait() do
 button.MouseEnter:Wait()
 --whatever
end

1 Like

:Wait() leaves a hanging thread and requires that there be nothing else after that loop (in your case).

A debounce would be better. However, I’ve always been a fan of:

local lastUsed = 0

EventName:connect(function()
    if tick() - lastUsed <= COOLDOWN then return end
    lastUsed = tick()
    -- code
end)

No particular reason, you could argue it’s more optimal than wait(COOLDOWN), but I just prefer it.

9 Likes

so tick is the best method?

Use whatever you prefer. I prefer tick() since it leaves no hanging threads.

1 Like

alright, thanks for the help! :slight_smile:

2 Likes