# Events

Events allow you to provide a function that will be run when an action occurs:

```lua
-- Execute entities when their health falls under 20
Events.EntityDamage(function(event)
    if (event.entity:getHealth() < 20) then
        event.entity.kill()
    end
end)
```

You can also modify (or sometimes cancel) event data:

```lua
-- Double all damage in the game after 15 minutes
Events.EntityDamage(function(event)
    local matchDurationSec = MatchService:getMatchDurationSec()
    if (matchDurationSec > 15 * 60) then
        event.damage = event.damage * 2
    end
end)
```

{% hint style="danger" %}
**WARNING:** Yielding in an event will delay the outcome of the event. Examples of yielding include `task.wait()`, while loops, using DataStoreService, or iterating over a very large set of objects.

It is **highly recommended** to use `task.spawn()`when waiting in an event.
{% endhint %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.easy.gg/scripting/bedwars-scripting/events.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
