# Example Script

{% code lineNumbers="true" %}

```lua
local juju = juju -- This is not neccessary.
    local create_connection = juju["create_connection"]
    local create_notification = juju["create_notification"]
local players_service = cloneref(game:GetService("Players"))
local player_image_data = base64_decode("")
    
local do_join_notification = function(player)
    create_notification(player["Name"].." has joined the server!", 2)
end

local do_leave_notification = function(player)
    create_notification(player["Name"].." has left the server!", 2)
end

-- >> ui toggle

local example_toggle = juju["create_element"]({
    ["name"] = "player join logs"
}, {
    ["toggle"] = {
        flag = "example",
        default = false
    }
})

-- >> core

local example_connection2 = nil
local example_connection = nil

create_connection(example_toggle["on_toggle_change"], function(bool)
    if example_connection then
        example_connection:Disconnect()
        example_connection = nil
    end
    
    if example_connection2 then
        example_connection2:Disconnect()
        example_connection2 = nil
    end

    if bool then
        example_connection = create_connection(players_service["PlayerAdded"], do_join_notification)
        example_connection2 = create_connection(players_service["PlayerRemoving"], do_leave_notification)
    end
end)

-- >> clean up

juju["on_unload"](function()
    print("bye bye :(")
    -- Notice we don't need to disconnect our connections above since we 
    -- used juju's built in create_connection function!
end)
```

{% endcode %}


---

# 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://addons.juju.lol/creating-a-script/necessities/example-script.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.
