> For the complete documentation index, see [llms.txt](https://tenfont.gitbook.io/skript/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://tenfont.gitbook.io/skript/script-tutorials/cooldown-on-event.md).

# Cooldown On Event

## Script Description

When we rightclick a block holding a stick, it will turn to bedrock. But we must wait 30 seconds before doing this again. If we don't, then it will send a message saying how long is left until we can do it again.

## Part 1: Creating The Event

Let's create our event. Since it's a right click, we're going to be using the **Right Click Event**.

{% code title="bedrock\_stick.sk" %}

```
on right click:
```

{% endcode %}

## Part 2: Creating The Cooldown

Creating a cooldown is very easy in Skript. Here is the idea behind it.

Basically, we'll set a variable to the time right now when the player right clicks. The next time the player right clicks, we can check how long they waited by checking the difference of the variable and the time right now. If they have waited long enough, we can execute the code, and reset the variable from earlier.

So, let's do this. I'm going to get the global list variable named `cooldown` and the `brstick::%player's uuid%` index of it. We're going to set a local variable named `waited` to the difference between the list variable and now. To do this we can use the `now` expression.

{% code title="bedrock\_stick.sk" %}

```
on right click:
    set {_waited} to difference between {cooldown::brstick::%player's uuid%} and now
```

{% endcode %}

## Part 3: How Long Is The Wait?

For this tutorial, I'm going to make it so the player will have to wait 30 seconds. To do this, in the next line, I'm going to add an `if statement` to check if our `wait` variable is less than 30 seconds. If it is, we'll send to the player how long they'll have to wait before right clicking again. Finally, we'll use the `stop` effect to stop the rest of the code from executing since the cooldown is not over yet.

{% code title="bedrock\_stick.sk" %}

```
on right click:
    set {_waited} to difference between {cooldown::brstick::%player's uuid%} and now
    if {_waited} is less than 30 seconds:
        send "Please wait %difference between 30 seconds and {_waited}% before doing this again."
        stop
```

{% endcode %}

## Part 4: Executing The Code

Now we can be sure that the player has waited 30 seconds when executing the next line of code. We're going to get the clicked block and set it to to bedrock. Then finally, we're going to reset the cooldown variable used in the second line.

{% code title="bedrock\_stick.sk" %}

```
on right click:
    set {_waited} to difference between {cooldown::brstick::%player's uuid%} and now
    if {_waited} is less than 30 seconds:
        send "Please wait %difference between 30 seconds and {_waited}% before doing this again."
        stop
    set event-block to bedrock
    set {cooldown::brstick::%player's uuid%} to now
```

{% endcode %}
