# Example Script 3

{% code overflow="wrap" lineNumbers="true" %}

```lua
-- >> variables

local juju = juju
    local create_connection = juju["create_connection"]
    local is_purchasing = juju["is_purchasing"]
    local purchase_item = juju["purchase_item"]
local players_service = cloneref(game:GetService("Players"))
    local local_player = players_service["LocalPlayer"]
    local local_character = local_player["Character"]
    local local_hrp = local_character and local_character:FindFirstChild("HumanoidRootPart") or nil

local on_local_character_loaded = juju["get_signal"]("on_local_character_loaded")
local find_first_child = workspace["FindFirstChild"]
local wait_for_child = workspace["WaitForChild"]
local heartbeat = cloneref(game:GetService("RunService"))["Heartbeat"]

-- >> get data 

local data_folder = wait_for_child(local_player, "DataFolder", 9e9)
    local information_folder = wait_for_child(data_folder, "Information", 9e9)
    local muscle_information = wait_for_child(information_folder, "MuscleInformation", 1) or {["Value"] = -150}
    
if not muscle_information then
    local connection = nil; connection = create_connection(information_folder["ChildAdded"], function(child)
        if child["Name"] == "MuscleInformation" then
            muscle_information = child
            connection:Disconnect()
        end
    end)
end

-- >> ui toggle

local toggle = juju["create_element"]({
    ["name"] = "auto skinny"
}, {
    ["toggle"] = {
        flag = "auto_skinny",
        default = false
    }
})

-- >> core

local character_added_connection = nil
local auto_skinny_connection = nil

local update_character_information = function()
    local_character = local_player["Character"]
    local_hrp = wait_for_child(local_character, "HumanoidRootPart", 9e9)
end

local do_auto_skinny = function()
    if not local_character or not local_hrp then
        return
    end

    local lettuce = find_first_child(local_player["Backpack"], "[Lettuce]") -- > not setting up caching for an example script f off

    if lettuce then
        lettuce["Parent"] = local_character
        lettuce:Activate()
        return
    end

    if tonumber(muscle_information["Value"]) > -15000 and not is_purchasing() then
        purchase_item("lettuce")
    end
end

create_connection(toggle["on_toggle_change"], function(value)
    if character_added_connection then
        character_added_connection:Disconnect()
        character_added_connection = nil
    end

    if auto_skinny_connection then
        auto_skinny_connection:Disconnect()
        auto_skinny_connection = nil
    end
    
    if value then
        character_added_connection = create_connection(on_local_character_loaded, update_character_information)
        auto_skinny_connection = create_connection(heartbeat, do_auto_skinny)
    end
end)

-- >> clean up

juju["on_unload"](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-3.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.
