Skip to content

Plugins ​

A plugin is a Luau file of your own that edits the world for you: the jobs that are tedious by hand, written once. Line these parts up, colour all of these, put a Prompt on every door, add a header to every script.

Where plugins live ​

In KHIM Engine's plugins folder: Plugins > Open the Plugins Folder. Each .luau file there is a plugin. An empty folder gets an example to read, Line up the selection.luau (Ctrl Alt L).

Run one from:

  • the Plugins menu,
  • the Plugins panel (View > Plugins),
  • the command palette (Ctrl K, "Run plugin: ..."),
  • or its own key.

Writing one ​

lua
-- Puts a Prompt on each selected door and selects the last one.
-- shortcut: Ctrl+Alt+P
for _, door in selection do
    local prompt = new("Prompt", door)
    prompt.text = "Open"
end
studio.select(selection[#selection])
studio.notify("Prompts on " .. #selection .. " doors")
  • The first comment line says what the plugin does; it is shown beside it in the menu, the panel and the palette.
  • -- shortcut: Ctrl+Alt+P among the first comments gives it a key: Ctrl or Alt (and Shift if you like), then a letter, a digit or F1-F12. Pick one KHIM Engine doesn't use (F1 lists them). The Plugins panel shows a line that names no valid key in amber.

What a plugin can use ​

A plugin runs on the world being edited, with the same API as a game's scripts - world, new, vec3, rgb, tags and attributes, everything in the Reference - plus:

NameWhat it is
selectionA list of the selected parts
studio.select(things)What is selected when the plugin ends: a part, an object, or a list of them
studio.notify(text)A message in the corner of the view
script.sourceA script's text - read and write it (only in plugins and the Command Line, never in a game)

It can change parts, Lighting, objects on parts (their settings, destroy(), new("Prompt", part)) and scripts (source, name). Everything it changed comes back into the world when it ends, as one Undo step.

More examples ​

lua
-- Paints the selection a random shade of green.
for _, part in selection do
    part.color = hsv(0.25 + math.random() * 0.1, 0.6, 0.5 + math.random() * 0.3)
end
lua
-- Tags every part in the world named Coin with "Coin".
for _, part in world:children() do
    if part.name == "Coin" then part:addTag("Coin") end
end
lua
-- Puts a header on the Door's script.
local door = world.Door.Script
door.source = "-- Opens when a player presses E\n" .. door.source

The Command Line ​

For a one-off job you don't need a file: the Command Line under the Console runs Luau on the world straight away, with the same API.

The .rbxl importer ​

The Plugins panel also has KHIM's built-in importer for .rbxl / .rbxlx worlds made in Roblox Studio. It is off until you switch it on there; then File > Import .rbxl / .rbxlx... appears. See Coming from Roblox.