# On Purchase

```lua
function yourEvent(user, receiptData)
    --possible types are: avatar, color, action, gear, nametag
    log(user.displayName .. ' bought ' .. receiptData.name);
    
    --if the type is gear, color, or action, 
    --that means there will be a ":" in the item name -> block_man:blue
    
    --you can use 
    --local blah = helper.split(receiptData.name, ':'); 
    --then the item name will be. -> blah[2] -> blue
    
    log('type of item: ' .. receiptData.type);
    log('currency cost: ' .. receiptData.cost);
    log('platformCurrency cost: ' .. receiptData.platformCurrencyCost);
    log('was the item a gift? ' .. tostring(receiptData.gifted));
end

return function()
    addEvent('receipts', 'yourEvent'); --attaches the event to yourEvent()
    keepAlive();
end
```

{% hint style="info" %}
Events are asynchronous coroutines.
{% 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.streamavatars.com/lua-scripting-api/api-reference-and-tips/events/on-purchase.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.
