> For the complete documentation index, see [llms.txt](https://addons.juju.lol/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://addons.juju.lol/creating-a-script/necessities/example-script-2.md).

# Example Script 2

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

```lua
-- >> variables

local juju = juju
    local get_flag = juju["get_flag"]
local delay = task["delay"]

-- >> core

local twod_hit_marker = juju["find_element"]("2d hit marker", "color")
local threed_hit_marker = juju["find_element"]("3d hit marker", "color")


local set_old = function(d2, d3)
    twod_hit_marker:set_colorpicker(d2)
    threed_hit_marker:set_colorpicker(d3)
end

local hit_callback = function(player, part)
    if part["Name"] == "Head" then
        local color = get_flag("hit_marker_headshot_color")
        local old_d2_color = get_flag("d2_hit_marker_color")
        local old_d3_color = get_flag("d3_hit_marker_color")
        twod_hit_marker:set_colorpicker(color)
        threed_hit_marker:set_colorpicker(color)
        delay(0, set_old, old_d2_color, old_d3_color) -- >> restore flags asap
    end
end

juju["create_element"]({
    ["name"] = "hit marker headshot color"
}, {
    ["colorpicker"] = {
        ["color_flag"] = "hit_marker_headshot_color",
        ["default_color"] = Color3.fromRGB(0,255,0),
        ["transparency_flag"] = "hit_marker_headshot_transparency",
        ["default_transparency"] = 0
    }
})

local signal = juju["get_signal"]("on_local_bullet_confirmed")
local callbacks = signal["callbacks"]

-- >> insert it as the first one so we can set the fflag before the hitmarker runs

for i = #callbacks, 1, -1 do
    callbacks[i + 1] = callbacks[i]
end
callbacks[1] = hit_callback

-- >> clean up 

juju["on_unload"](function()
    -- >> remove callback and restore old table positions
    for i = 1, #callbacks - 1 do
        callbacks[i] = callbacks[i + 1] 
    end
    callbacks[#callbacks] = nil
end)

-- >> loaded 

juju["create_notification"]("loaded hitmarker head color lua by xander", 1)
```

{% endcode %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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-2.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.
