Getting Started

Before you can jump into creating an addon; there's a few things you need to know.

How to properly unload your addon

Lua is limited and because of this we are required to have a few tedious steps to ensure proper unloading.

You must connect to a signal that fires when an addon is unloaded, this signal is fired with one argument, that being the file name of the addon.

The purpose for this is so you can properly disconnect connections, remove drawing objects and anything that may linger after your addon's thread is stopped.

Example

-- // File name is "spam.lua"

local connections = {}
local drawings = {}

local function newConnection(signal, callback)
    local connection = signal:Connect(callback)
    connections[#connections+1] = connection
    
    return connection
end

local function newDrawing(class, properties)
    local object = Drawing.new(class)
    
    for property, value in properties do
        object[property] = value
    end
    
    drawings[#drawings+1] = object
    
    return object
end

newConnection(game:GetService("RunService").Heartbeat, function(dt)
    print(dt)
end)

do
    local viewport_size = workspace.CurrentCamera.ViewportSize
    newDrawing("Square", {
        Visible = true;
        Transparency = 0.5;
        Size = viewport_size/2;
        Position = viewport_size/4;
        Color = Color3.fromRGB(255,255,255)
    })
end

newConnection(juju.script_unloaded, function(key) -- the juju table is global!
    if key == "spam" then
        for _, connection in connections do
            connection:Disconnect()
        end 
        for _, drawing in drawings do
            drawing:Destroy()
        end
    end 
end)

Last updated