🏠 Home 📋 Roadmap 💬 Discord 💻 GitHub

Nebrix Lua API Documentation

Complete reference for scripting games in Nebrix using Lua. Build 3D worlds, apply physics, create GUIs, and more.

Lua 5.4 API v1.0 Case-insensitive properties

Introduction

Nebrix uses Lua 5.4 as its scripting language. This API is designed to feel familiar to developers from other game engines while providing powerful features for creating 3D games.

Note: All property names are case-insensitive — Position and position both work.

Quick Start

Here's a simple example to get you started:

-- Create a red part
local part = Instance.new("Part", workspace)
part.Position = Vector3.new(0, 10, 0)
part.Color = Color3.fromRGB(255, 0, 0)
part.Size = Vector3.new(4, 1, 2)

-- Add physics
part.Anchored = false
part:ApplyImpulse(Vector3.new(0, 50, 0))

-- Update loop (called every frame)
function onUpdate(dt)
    part:Rotate(Vector3.new(0, 1, 0))
end

Vector3

Represents a 3D vector with X, Y, and Z components.

Vector3.new(x, y, z) → Vector3

Creates a new Vector3. All parameters default to 0.

x — The X component
y — The Y component
z — The Z component
local position = Vector3.new(10, 5, 0)
local up = Vector3.new(0, 1, 0)

Constants

  • Vector3.zero — Shorthand for Vector3.new(0, 0, 0)
  • Vector3.one — Shorthand for Vector3.new(1, 1, 1)

Properties

PropertyTypeDescription
X or xnumberThe X component
Y or ynumberThe Y component
Z or znumberThe Z component

Vector2

Represents a 2D vector with X and Y components. Used for GUI positioning and sizing.

Vector2.new(x, y) → Vector2

Creates a new Vector2.

local guiPos = Vector2.new(100, 50)
  • Vector2.zero — Equals Vector2.new(0, 0)
  • Vector2.one — Equals Vector2.new(1, 1)

Color3

Represents an RGB color with values from 0 to 1 (or 0–255 with fromRGB).

Color3.new(r, g, b) → Color3

Creates a Color3 with normalized values (0 to 1).

local white = Color3.new(1, 1, 1)
local black = Color3.new(0, 0, 0)
Color3.fromRGB(r, g, b) → Color3

Creates a Color3 from 0–255 values.

local red = Color3.fromRGB(255, 0, 0)
local blue = Color3.fromRGB(0, 100, 255)
Color3.fromHSV(h, s, v) → Color3

Creates a Color3 from HSV values (all 0–1).

local cyan = Color3.fromHSV(0.5, 1, 1)

Properties

  • R or r — Red component (0–1)
  • G or g — Green component (0–1)
  • B or b — Blue component (0–1)

Instance

Base class for all objects in Nebrix.

Instance.new(className, parent?) → Instance

Creates a new instance of the specified type.

className — "Part", "Sphere", "Cylinder", "Wedge", "Model", "Folder", "Script", "Frame", "TextLabel", "TextButton"
parent — Optional parent object
local part = Instance.new("Part", workspace)
local model = Instance.new("Model", workspace)
local frame = Instance.new("Frame", game.PlayerGui)

Properties

PropertyTypeDescription
NamestringThe name of the instance
ParentInstanceThe parent object
ClassNamestringThe type of the instance (read-only)

Methods

:IsA(className) → boolean

Checks if the instance is of the specified type.

if part:IsA("Part") then
    print("This is a part!")
end
:FindFirstChild(name) → Instance?

Returns the first child with the specified name, or nil.

local head = character:FindFirstChild("Head")
:WaitForChild(name) → Instance?

Returns the first child with the specified name (currently same as FindFirstChild).

:GetChildren() → {Instance}

Returns an array of all children.

for i, child in pairs(workspace:GetChildren()) do
    print(child.Name)
end

Part

A 3D physical object with shape, position, and physics properties. Supported types: Part, Sphere, Cylinder, Wedge.

Properties

PropertyTypeDescription
PositionVector3World position of the part
RotationVector3Rotation in degrees (X, Y, Z)
SizeVector3Dimensions of the part
ColorColor3The color of the part
Transparencynumber0 = opaque, 1 = invisible
AnchoredbooleanIf true, physics won't move the part
CanCollidebooleanWhether physics collisions occur
MassnumberThe mass for physics calculations
VelocityVector3Current velocity vector
local part = Instance.new("Part", workspace)
part.Position = Vector3.new(0, 10, 0)
part.Size = Vector3.new(4, 1, 2)
part.Color = Color3.fromRGB(100, 150, 255)
part.Transparency = 0.5
part.Anchored = false
part.CanCollide = true
part.Mass = 10

Physics Methods

:SetPosition(position: Vector3)

Instantly sets the position of the part.

part:SetPosition(Vector3.new(10, 5, 0))
:Translate(offset: Vector3)

Moves the part by the specified offset.

part:Translate(Vector3.new(0, 5, 0))
:SetRotation(rotation: Vector3)

Sets the rotation in degrees.

part:SetRotation(Vector3.new(0, 45, 0))
:LookAt(position: Vector3)

Rotates the part to face the target position.

part:LookAt(Vector3.new(10, 0, 10))
:ApplyImpulse(impulse: Vector3)

Applies an instant impulse (impulse / mass = velocity change).

part:ApplyImpulse(Vector3.new(0, 100, 0))
:ApplyForce(force: Vector3)

Applies continuous force over time (uses delta time). Best called inside onUpdate.

function onUpdate(dt)
    part:ApplyForce(Vector3.new(0, 50, 0))
end
:AddVelocity(velocity: Vector3)

Directly adds to the part's current velocity.

part:AddVelocity(Vector3.new(5, 0, 0))
:GetVelocity() → Vector3

Returns the current velocity of the part.

local vel = part:GetVelocity()
print("Speed:", vel.Y)
:IsGrounded() → boolean

Returns true if the part is currently touching the ground.

if part:IsGrounded() then
    print("On ground!")
end
:GetForwardVector() → Vector3

Returns the forward direction vector based on current rotation.

local forward = part:GetForwardVector()
part:Translate(forward)
:GetUpVector() → Vector3

Returns the up direction vector (always 0, 1, 0).

Model & Folder

Containers for organizing multiple objects in the game hierarchy.

local car = Instance.new("Model", workspace)
car.Name = "Car"

local body = Instance.new("Part", car)
body.Name = "Body"
body.Size = Vector3.new(4, 2, 6)

local wheel = Instance.new("Cylinder", car)
wheel.Name = "Wheel"

GUI Elements

Create in-game user interfaces with Frame, TextLabel, and TextButton.

Frame

local frame = Instance.new("Frame", game.PlayerGui)
frame.Size = Vector2.new(200, 100)
frame.Position = Vector2.new(50, 50)
frame.BackgroundColor3 = Color3.fromRGB(50, 50, 50)

TextLabel

local label = Instance.new("TextLabel", frame)
label.Text = "Hello Nebrix!"
label.Size = Vector2.new(200, 50)
label.Position = Vector2.new(0, 0)

TextButton

button.Clicked = function()

Set a function to handle button click events.

local button = Instance.new("TextButton", frame)
button.Text = "Click Me"
button.Size = Vector2.new(150, 40)

button.Clicked = function()
    print("Button was clicked!")
end

GUI Properties

PropertyTypeDescription
SizeVector2Width and height in pixels
PositionVector2X and Y position in pixels
BackgroundColor3Color3Background color
TextstringText content (Label/Button only)
VisiblebooleanWhether the element is visible

game

The root of the game hierarchy. Use it to access services and global containers.

game:GetService(serviceName) → Service

Returns the specified service by name.

local workspace = game:GetService("Workspace")
local lighting = game:GetService("Lighting")
local gui = game:GetService("PlayerGui")

Direct Properties

  • game.Workspace — The 3D world container
  • game.Lighting — Lighting and atmosphere settings
  • game.ScriptService — Container for scripts
  • game.PlayerGui — Container for GUI elements

Workspace

The 3D world where all parts and models exist. Accessible via workspace or game.Workspace.

-- Both of these work:
local part = Instance.new("Part", workspace)
local part2 = Instance.new("Part", game.Workspace)

Lighting

Controls the lighting, atmosphere, and time of day in your game.

Properties

PropertyTypeDescription
TimeOfDaynumberTime in hours (0–24)
BrightnessnumberOverall brightness multiplier
AmbientColor3Ambient light color
OutdoorAmbientColor3Outdoor ambient light color
FogStartnumberDistance where fog starts
FogEndnumberDistance where fog is fully opaque
FogColorColor3Color of the fog
local lighting = game.Lighting
lighting.TimeOfDay = 18.5
lighting.Brightness = 2
lighting.Ambient = Color3.fromRGB(150, 100, 100)
lighting.FogStart = 50
lighting.FogEnd = 500
lighting.FogColor = Color3.fromRGB(200, 200, 220)
:SetTimeOfDay(time: number)

Sets the time of day (0–24).

function onUpdate(dt)
    local lighting = game.Lighting
    lighting:SetTimeOfDay(lighting.TimeOfDay + dt * 0.1)
    if lighting.TimeOfDay > 24 then
        lighting.TimeOfDay = 0
    end
end

Math Extensions

Extended math functions beyond the standard Lua math library.

math.clamp(value, min, max) → number

Clamps a value between min and max.

local speed = math.clamp(speed, 0, 100)
math.lerp(a, b, t) → number

Linear interpolation between a and b.

local pos = math.lerp(0, 100, 0.5) -- Returns 50
math.sign(value) → number

Returns -1, 0, or 1 depending on the sign of the value.

local dir = math.sign(-5) -- Returns -1
math.round(value) → number

Rounds to the nearest integer.

local rounded = math.round(4.7) -- Returns 5
math.randomFloat(min, max) → number

Returns a random float between min and max.

local speed = math.randomFloat(1.0, 5.0)
math.map(value, inMin, inMax, outMin, outMax) → number

Maps a value from one range to another.

local n = math.map(50, 0, 100, 0, 1) -- Returns 0.5
math.distance(vec1, vec2) → number

Returns the distance between two Vector3 points.

local dist = math.distance(
    Vector3.new(0, 0, 0),
    Vector3.new(10, 0, 0)
) -- Returns 10

Table Extensions

Additional table manipulation functions.

table.find(tbl, value) → number?

Returns the index of value in the table, or nil if not found.

local fruits = {"apple", "banana", "orange"}
local i = table.find(fruits, "banana") -- Returns 2
table.getn(tbl) → number

Returns the length of the table.

local count = table.getn({1, 2, 3, 4}) -- Returns 4
table.clear(tbl)

Removes all elements from the table.

local list = {1, 2, 3}
table.clear(list) -- list is now {}
table.clone(tbl) → table

Creates a shallow copy of the table.

local copy = table.clone({a = 1, b = 2})
table.merge(tbl1, tbl2) → table

Creates a new table merging both inputs.

local merged = table.merge({a=1}, {b=2}) -- {a=1, b=2}
table.shuffle(tbl) → table

Randomly shuffles the table in place and returns it.

local deck = {1, 2, 3, 4, 5}
table.shuffle(deck)

String Extensions

Additional string manipulation functions.

string.split(str, separator) → {string}
local parts = string.split("a,b,c", ",") -- {"a","b","c"}
string.trim(str) → string

Removes leading and trailing whitespace.

string.trim("  hello  ") -- "hello"
string.startswith(str, prefix) → boolean
string.startswith("player_1", "player_") -- true
string.endswith(str, suffix) → boolean
string.endswith("game.lua", ".lua") -- true
string.replace(str, find, replace) → string
string.replace("Hello World", "World", "Nebrix")
-- "Hello Nebrix"

Task Library

Functions for managing asynchronous tasks and timing.

task.wait()

Yields execution. Also available as the global wait().

Note: The task library is minimal in the current version. More scheduling features are planned for future releases.

Global Functions

print(...)

Outputs messages to the console.

print("Hello, Nebrix!")
print("Position:", part.Position)
warn(message)

Outputs a warning message to the console.

error(message)

Throws an error and stops execution.

onUpdate(dt: number)

Called every frame if defined in your script. dt is delta time in seconds.

function onUpdate(dt)
    part.Rotation = part.Rotation + Vector3.new(0, 90 * dt, 0)
end

Global Variables

  • script — Reference to the current script object
  • workspace — Shorthand for game.Workspace

Complete Examples

Spinning Part

local part = Instance.new("Part", workspace)
part.Position = Vector3.new(0, 10, 0)
part.Color = Color3.fromRGB(255, 100, 100)
part.Anchored = true

function onUpdate(dt)
    part.Rotation = part.Rotation + Vector3.new(0, 45 * dt, 0)
end

Bouncing Ball

local ball = Instance.new("Sphere", workspace)
ball.Position = Vector3.new(0, 50, 0)
ball.Size = Vector3.new(2, 2, 2)
ball.Color = Color3.fromRGB(100, 150, 255)
ball.Anchored = false
ball.CanCollide = true

function onUpdate(dt)
    if ball:IsGrounded() then
        local vel = ball:GetVelocity()
        if vel.Y < 0 then
            ball:ApplyImpulse(Vector3.new(0, 80, 0))
        end
    end
end

Simple Button Counter

local count = 0

local frame = Instance.new("Frame", game.PlayerGui)
frame.Size = Vector2.new(200, 100)
frame.Position = Vector2.new(10, 10)
frame.BackgroundColor3 = Color3.fromRGB(40, 40, 40)

local label = Instance.new("TextLabel", frame)
label.Size = Vector2.new(200, 50)
label.Text = "Count: 0"

local button = Instance.new("TextButton", frame)
button.Size = Vector2.new(200, 40)
button.Position = Vector2.new(0, 55)
button.Text = "Click Me!"
button.BackgroundColor3 = Color3.fromRGB(225, 29, 72)

button.Clicked = function()
    count = count + 1
    label.Text = "Count: " .. count
end

Day/Night Cycle

local lighting = game.Lighting
lighting.TimeOfDay = 12

function onUpdate(dt)
    lighting.TimeOfDay = lighting.TimeOfDay + dt * 0.1
    if lighting.TimeOfDay >= 24 then
        lighting.TimeOfDay = 0
    end

    local time = lighting.TimeOfDay
    if time > 6 and time < 18 then
        lighting.Brightness = 2
    else
        lighting.Brightness = 0.3
    end
end