local debounce = false
: Initializes a variable debounce
to false
. This variable will be used to prevent rapid consecutive button clicks.
local function onButtonClicked()
: Defines a function named onButtonClicked
which will be executed when the button is clicked.
if not debounce then
: Checks if debounce
is false
. This conditional statement ensures that the code inside the if
block is only executed if debounce
is false
, preventing multiple rapid clicks.
debounce = true
: Sets debounce
to true
to indicate that a click has been registered, preventing further rapid clicks until it's reset.
print("Button clicked!")
: Placeholder for the action to be performed when the button is clicked.
wait(2)
: Pauses the execution of the code for 2 seconds. This simulates some action being performed after the button click.
debounce = false
: Resets debounce
to false
after the action and the wait period are completed. This allows the button to be clicked again.
button.MouseButton1Click:Connect(onButtonClicked)
: Connects the onButtonClicked
function to the button's MouseButton1Click
event. When the button is clicked (MouseButton1Click
), the onButtonClicked
function will be called.
```