# External Loader

{% hint style="info" %}
**Concept:** Your external loader validates the key using Junkie UI-Library, then loads the actual script from Junkie CDN using the validated key in `getgenv().SCRIPT_KEY`
{% endhint %}

***

{% stepper %}
{% step %}
**Create External Loader**

Build a loader script and host it on GitHub, Pastebin, or your own server:

```
-- Load library
local Junkie = loadstring(game:HttpGet("https://jnkie.com/sdk/library.lua"))()
Junkie.service = "YOUR_SERVICE"
Junkie.identifier = "12345" 
Junkie.provider = "Mixed"

-- UI Implementation
local validatedKey = nil

-- Show custom UI 
local function showUI()
    local link = Junkie.get_key_link()
    if link then
        setclipboard(link)  -- Copy to clipboard
        print("Link copied to clipboard!")
    else
        warn("Wait 5 minutes")
        return nil
    end
    
    -- Wait for user to input key (your UI logic here)
    local userKey = promptUserForKey()  -- Replace with your UI input
    
    if userKey then
        local validation = Junkie.check_key(userKey)
        if validation.valid then
            return userKey
        else
            warn("Error: " .. (validation.error or "Invalid key"))
            return nil
        end
    end
end

validatedKey = showUI()

if not validatedKey then
    warn("No valid key provided")
    return
end

-- Store key globally for Junkie script to use
getgenv().SCRIPT_KEY = validatedKey

-- Now load the actual Junkie script
loadstring(game:HttpGet("https:/api.jnkie.com/api/v1/luascripts/..."))()
```

{% endstep %}

{% step %}
**User Workflow**

How users will execute your script:

```
User loads external loader:
loadstring(game:HttpGet("https://your-loader-url.com/loader.lua"))()
Loader shows UI and validates key using Junkie.check_key()
Loader stores key in getgenv().SCRIPT_KEY
Loader loads Junkie script which reads the key from getgenv()
Main script runs with validated key
```

{% endstep %}

{% step %}
**Complete Production Example**

```
local Junkie = loadstring(game:HttpGet("https://jnkie.com/sdk/library.lua"))()
Junkie.service = "Premium Hub"
Junkie.identifier = "12345"
Junkie.provider = "Mixed"

local maxAttempts = 5
local attempts = 0
local validated = false

while not validated and attempts < maxAttempts do
    local link = Junkie.get_key_link()
    if link then
        if setclipboard then
            setclipboard(link)
        end
    else
        warn("Please wait 5 minutes")
    end
    
    -- Get user input (replace with your UI)
    print("\nEnter your key:")
    local userKey = getUserInput()  -- Your UI logic
    
    if userKey and #userKey > 0 then
        attempts = attempts + 1
        
        local validation = Junkie.check_key(userKey)
        if validation.valid then
            validated = true
            getgenv().SCRIPT_KEY = userKey
            print("\nKey validated successfully!")
            break
        else
            local errorMsg = validation.message or "Unknown error"
            warn("[ERROR] " .. errorMsg)
            
            -- Handle specific backend error messages
            if errorMsg == "KEY_EXPIRED" then
                print("[INFO] Key expired - get a new one")
            elseif errorMsg == "HWID_BANNED" then
                game.Players.LocalPlayer:Kick("Hardware banned")
                return
            elseif errorMsg == "SERVICE_MISMATCH" then
                print("[INFO] Key is for a different service")
            elseif errorMsg == "HWID_MISMATCH" then
                print("[INFO] HWID limit reached")
            end
        end
    else
        warn("Error: No key entered")
    end
    
    if attempts >= maxAttempts then
        warn("Error: Too many failed attempts!")
        return
    end
    
    task.wait(1)
end

if not validated then
    warn("Error: Validation failed")
    return
end

-- Load main script
loadstring(game:HttpGet("https://api.jnkie.com/api/v1/luascripts/.../download"))()
```

{% endstep %}
{% endstepper %}


---

# 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.jnkie.com/roblox-sdk/external-loader.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.
