Nebrix Lua API Documentation
Complete reference for scripting games in Nebrix using Lua. Build 3D worlds, apply physics, create GUIs, and more.
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.
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.
Creates a new Vector3. All parameters default to 0.
local position = Vector3.new(10, 5, 0)
local up = Vector3.new(0, 1, 0)
Constants
Vector3.zero— Shorthand forVector3.new(0, 0, 0)Vector3.one— Shorthand forVector3.new(1, 1, 1)
Properties
| Property | Type | Description |
|---|---|---|
X or x | number | The X component |
Y or y | number | The Y component |
Z or z | number | The Z component |
Vector2
Represents a 2D vector with X and Y components. Used for GUI positioning and sizing.
Creates a new Vector2.
local guiPos = Vector2.new(100, 50)
Vector2.zero— EqualsVector2.new(0, 0)Vector2.one— EqualsVector2.new(1, 1)
Color3
Represents an RGB color with values from 0 to 1 (or 0–255 with fromRGB).
Creates a Color3 with normalized values (0 to 1).
local white = Color3.new(1, 1, 1)
local black = Color3.new(0, 0, 0)
Creates a Color3 from 0–255 values.
local red = Color3.fromRGB(255, 0, 0)
local blue = Color3.fromRGB(0, 100, 255)
Creates a Color3 from HSV values (all 0–1).
local cyan = Color3.fromHSV(0.5, 1, 1)
Properties
Rorr— Red component (0–1)Gorg— Green component (0–1)Borb— Blue component (0–1)
Instance
Base class for all objects in Nebrix.
Creates a new instance of the specified type.
local part = Instance.new("Part", workspace)
local model = Instance.new("Model", workspace)
local frame = Instance.new("Frame", game.PlayerGui)
Properties
| Property | Type | Description |
|---|---|---|
Name | string | The name of the instance |
Parent | Instance | The parent object |
ClassName | string | The type of the instance (read-only) |
Methods
Checks if the instance is of the specified type.
if part:IsA("Part") then
print("This is a part!")
end
Returns the first child with the specified name, or nil.
local head = character:FindFirstChild("Head")
Returns the first child with the specified name (currently same as FindFirstChild).
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
| Property | Type | Description |
|---|---|---|
Position | Vector3 | World position of the part |
Rotation | Vector3 | Rotation in degrees (X, Y, Z) |
Size | Vector3 | Dimensions of the part |
Color | Color3 | The color of the part |
Transparency | number | 0 = opaque, 1 = invisible |
Anchored | boolean | If true, physics won't move the part |
CanCollide | boolean | Whether physics collisions occur |
Mass | number | The mass for physics calculations |
Velocity | Vector3 | Current 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
Instantly sets the position of the part.
part:SetPosition(Vector3.new(10, 5, 0))
Moves the part by the specified offset.
part:Translate(Vector3.new(0, 5, 0))
Sets the rotation in degrees.
part:SetRotation(Vector3.new(0, 45, 0))
Rotates the part to face the target position.
part:LookAt(Vector3.new(10, 0, 10))
Applies an instant impulse (impulse / mass = velocity change).
part:ApplyImpulse(Vector3.new(0, 100, 0))
Applies continuous force over time (uses delta time). Best called inside onUpdate.
function onUpdate(dt)
part:ApplyForce(Vector3.new(0, 50, 0))
end
Directly adds to the part's current velocity.
part:AddVelocity(Vector3.new(5, 0, 0))
Returns the current velocity of the part.
local vel = part:GetVelocity()
print("Speed:", vel.Y)
Returns true if the part is currently touching the ground.
if part:IsGrounded() then
print("On ground!")
end
Returns the forward direction vector based on current rotation.
local forward = part:GetForwardVector()
part:Translate(forward)
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
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
| Property | Type | Description |
|---|---|---|
Size | Vector2 | Width and height in pixels |
Position | Vector2 | X and Y position in pixels |
BackgroundColor3 | Color3 | Background color |
Text | string | Text content (Label/Button only) |
Visible | boolean | Whether the element is visible |
game
The root of the game hierarchy. Use it to access services and global containers.
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 containergame.Lighting— Lighting and atmosphere settingsgame.ScriptService— Container for scriptsgame.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
| Property | Type | Description |
|---|---|---|
TimeOfDay | number | Time in hours (0–24) |
Brightness | number | Overall brightness multiplier |
Ambient | Color3 | Ambient light color |
OutdoorAmbient | Color3 | Outdoor ambient light color |
FogStart | number | Distance where fog starts |
FogEnd | number | Distance where fog is fully opaque |
FogColor | Color3 | Color 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)
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.
Clamps a value between min and max.
local speed = math.clamp(speed, 0, 100)
Linear interpolation between a and b.
local pos = math.lerp(0, 100, 0.5) -- Returns 50
Returns -1, 0, or 1 depending on the sign of the value.
local dir = math.sign(-5) -- Returns -1
Rounds to the nearest integer.
local rounded = math.round(4.7) -- Returns 5
Returns a random float between min and max.
local speed = math.randomFloat(1.0, 5.0)
Maps a value from one range to another.
local n = math.map(50, 0, 100, 0, 1) -- Returns 0.5
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.
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
Returns the length of the table.
local count = table.getn({1, 2, 3, 4}) -- Returns 4
Removes all elements from the table.
local list = {1, 2, 3}
table.clear(list) -- list is now {}
Creates a shallow copy of the table.
local copy = table.clone({a = 1, b = 2})
Creates a new table merging both inputs.
local merged = table.merge({a=1}, {b=2}) -- {a=1, b=2}
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.
local parts = string.split("a,b,c", ",") -- {"a","b","c"}
Removes leading and trailing whitespace.
string.trim(" hello ") -- "hello"
string.startswith("player_1", "player_") -- true
string.endswith("game.lua", ".lua") -- true
string.replace("Hello World", "World", "Nebrix")
-- "Hello Nebrix"
Task Library
Functions for managing asynchronous tasks and timing.
Yields execution. Also available as the global wait().
Global Functions
Outputs messages to the console.
print("Hello, Nebrix!")
print("Position:", part.Position)
Outputs a warning message to the console.
Throws an error and stops execution.
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 objectworkspace— Shorthand forgame.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