How to make a button not spammable

hi everyone i need help to make a button not spammable its a button that gives you coins i want to make it so you have to wait 2 sec to click it again but i dont know how to make it can anyone help

make a debounce

local debounce = true

button.MouseButton1Click:Connect(function()
     if debounce == true then
          debounce = false
          --do your stuff here
          wait(2)
          debounce = true
     end
end)

thank you alot i havent worked with debounce before seems like it helps gona look it up for more info have a great day

1 Like