Skip to main content
Reading time: ~40 minutes (reference material)
Complete API documentation for CORP (Component-Oriented Replicated Programming).

Table of Contents


Core Classes

CORP

Main entry point for the framework.

Methods

CORP.start(configuration: Configurations.GameConfiguration): void
Starts CORP with a configuration object.
CORP.start({
    startingScene: MyScene
});
Parameters:
  • configuration.startingScene - Scene description or path to scene
CORP.startFromWorkspace(): void
Starts CORP using existing workspace instances (for rapid prototyping).
CORP.startFromWorkspace();

GameObject

Represents an entity in the game world. Container for Components.

Constructor

new GameObject(name: string)
Parameters:
  • name - Name of the GameObject

Properties

PropertyTypeDescription
componentAddedSignal<[Component]>Fires when a component is added
componentRemovingSignal<[Component]>Fires when a component is removing
componentSpawnedSignal<[Component]>Fires when a component spawns (NetworkBehaviors)
removingSignal<[]>Fires when GameObject is being destroyed
ancestryChangedSignal<[GameObject, GameObject | Scene | undefined]>Fires when parent changes
isDestroyingbooleanWhether the GameObject is currently being destroyed

Methods

addComponent<T>(clazz: Constructable<T>, config?: ComponentConfig<T>): T
Adds a component to the GameObject.
const health = player.addComponent(HealthSystem, {
    maxHealth: 100
});
Parameters:
  • clazz - Component class to add
  • config - Optional configuration object
Returns: The added component instance
getComponent<T>(clazz: Constructable<T> | string): T | undefined
Gets a component from the GameObject.
const health = player.getComponent(HealthSystem);
Parameters:
  • clazz - Component class or path string
Returns: Component instance or undefined
hasComponent<T>(clazz: Constructable<T>): boolean
Checks if GameObject has a component.
if (player.hasComponent(HealthSystem)) {
    // Has health component
}
Parameters:
  • clazz - Component class to check
Returns: True if component exists
removeComponent<T>(clazz: Constructable<T>): void
Removes a component from the GameObject.
player.removeComponent(HealthSystem);
Parameters:
  • clazz - Component class to remove
destroy(): void
Destroys the GameObject and all its components.
enemy.destroy();
setParent(parent: GameObject | Scene | undefined): void
Sets the parent of this GameObject.
child.setParent(parent);
Parameters:
  • parent - New parent GameObject, Scene, or undefined
getParent(): GameObject | Scene | undefined
Gets the parent of this GameObject.
const parent = child.getParent();
Returns: Parent GameObject, Scene, or undefined
getChildren(): GameObject[]
Gets all child GameObjects.
const children = parent.getChildren();
Returns: Array of child GameObjects
getDescendants(): GameObject[]
Gets all descendant GameObjects recursively.
const all = root.getDescendants();
Returns: Array of all descendant GameObjects
getTransform(): CFrame
Gets the transform (position and rotation) of the GameObject.
const transform = player.getTransform();
Returns: CFrame representing the transform
setTransform(transform: CFrame): void
Sets the transform of the GameObject.
player.setTransform(new CFrame(0, 10, 0));
Parameters:
  • transform - New CFrame transform
getPosition(): Vector3
Gets the position of the GameObject.
const pos = player.getPosition();
Returns: Vector3 position
getName(): string
Gets the name of the GameObject.
const name = player.getName();
Returns: GameObject name
getInstance(): Actor
Gets the underlying Roblox Instance.
const instance = player.getInstance();
Returns: Actor instance

Static Methods

GameObject.fromInstance(instance: Actor, name: string): GameObject
Creates a GameObject from an existing Roblox Instance.
const actor = new Instance("Actor");
const gameObject = GameObject.fromInstance(actor, "MyObject");
Parameters:
  • instance - Roblox Actor instance
  • name - Name for the GameObject
Returns: New GameObject
GameObject.importGameObject(description: GameObjectDescription, parent: GameObject | Scene, isClient: boolean): GameObject
Imports a GameObject from a scene description.

Component

Abstract base class for all components.

Constructor

public constructor(gameObject: GameObject, initOnCreated?: boolean)
Parameters:
  • gameObject - GameObject this component is attached to
  • initOnCreated - Whether to initialize immediately (default: true)

Properties

PropertyTypeDescription
executionOrdernumberOrder in which component is initialized (lower = earlier)
removingSignal<[]>Fires when component is about to be removed

Methods

abstract onStart(): void
Called when the component starts. Must be implemented.
public onStart(): void {
    // Initialization logic
}
abstract willRemove(): void
Called before the component is removed. Must be implemented.
public willRemove(): void {
    // Cleanup logic
}
abstract getSourceScript(): LuaSourceContainer
Returns the script that defines this component. Must be implemented.
protected getSourceScript(): ModuleScript {
    return script as ModuleScript;
}
willStart(): void
Called before onStart. Override for pre-initialization.
public willStart(): void {
    // Pre-initialization logic
}
onPropertiesApplied(): void
Called after properties are applied via serialization. Override to react to configuration.
public onPropertiesApplied(): void {
    // React to configured properties
}
initialize(): void
Initializes the component. Called internally by CORP.
remove(): void
Removes and destroys this component.
component.remove();
getGameObject(): GameObject
Gets the GameObject this component is attached to.
const gameObject = this.getGameObject();
Returns: GameObject instance
Component Shortcuts
These methods are shortcuts to GameObject methods:
this.getTransform()           // GameObject.getTransform()
this.setTransform(cframe)     // GameObject.setTransform()
this.getPosition()            // GameObject.getPosition()
this.getName()                // GameObject.getName()
this.getInstance()            // GameObject.getInstance()
this.getComponent(clazz)      // GameObject.getComponent()
this.destroy()                // GameObject.destroy()

Behavior

Extends Component with serialization support. Use this as the base for most components.

All Component Methods

Behavior inherits all methods from Component.

Methods

serializeState(): Partial<Behavior>
Returns the serialized state of all @SerializeField properties.
const state = this.serializeState();
Returns: Object containing serialized field values

Properties

PropertyTypeDescription
collectorCollectorGarbage collector for automatic resource cleanup

Networking Classes

NetworkObject

Makes a GameObject replicate across the network.

Constructor

public constructor(gameObject: GameObject)

Properties

PropertyTypeDescription
ownerChangedSignal<[Player | undefined]>Fires when ownership changes
isLoadedChangedSignal<[boolean]>Fires when loaded state changes

Methods

spawn(): void
Spawns the NetworkObject on the network (server only).
if (RunService.IsServer()) {
    netObj.spawn();
}
changeOwnership(owner: Player | undefined): void (Server Only)
Changes the owner of this NetworkObject.
netObj.changeOwnership(player); // Give to player
netObj.changeOwnership(undefined); // Give to server
Parameters:
  • owner - New owner Player, or undefined for server
getOwner(): Player | undefined
Gets the current owner.
const owner = netObj.getOwner();
Returns: Owner Player or undefined (server owned)
getId(): string
Gets the unique network ID.
const id = netObj.getId();
Returns: Network ID string

NetworkBehavior

Network-replicated component. Requires NetworkObject.

Constructor

public constructor(gameObject: GameObject, initOnCreated?: boolean)

All Behavior Methods

NetworkBehavior inherits all methods from Behavior.

Methods

getNetworkObject(): NetworkObject
Gets the associated NetworkObject.
const netObj = this.getNetworkObject();
Returns: NetworkObject component
getId(): string
Gets the unique network behavior ID.
const id = this.getId();
Returns: Network behavior ID

NetworkedVariable

Replicated variable that synchronizes between server and clients.

Constructor

new NetworkedVariable<T>(initialValue?: T, config?: NetworkVariableConfig)
Parameters:
  • initialValue - Initial value
  • config - Configuration options
Config Options:
interface NetworkVariableConfig {
    replicationBehavior?: NetworkVariableReplicationBehavior; // BATCHED or INSTANTANEOUS
}

Properties

PropertyTypeDescription
onValueChangedSignal<[T, T]>Fires when value changes (newValue, oldValue)

Methods

getValue(): T
Gets the current value.
const value = myVar.getValue();
Returns: Current value
setValue(value: T): void (Server Only)
Sets the value (server only).
if (RunService.IsServer()) {
    myVar.setValue(100);
}
Parameters:
  • value - New value

NetworkedList

Replicated list/array.

Constructor

new NetworkedList<T>(config?: NetworkVariableConfig)

Properties

PropertyTypeDescription
onItemAddedSignal<[T, number]>Fires when item is added (item, index)
onItemRemovedSignal<[T, number]>Fires when item is removed (item, index)
onItemSetSignal<[T, number]>Fires when item is set (item, index)

Methods

push(item: T): void (Server Only)
Adds an item to the end.
list.push("item");
remove(index: number): T | undefined (Server Only)
Removes an item at index.
const removed = list.remove(0);
get(index: number): T | undefined
Gets an item at index.
const item = list.get(0);
set(index: number, value: T): void (Server Only)
Sets an item at index.
list.set(0, "newValue");
size(): number
Gets the size of the list.
const size = list.size();

NetworkedMap

Replicated map/dictionary.

Constructor

new NetworkedMap<K, V>(config?: NetworkVariableConfig)

Properties

PropertyTypeDescription
onKeySetSignal<[K, V]>Fires when key is set
onKeyDeletedSignal<[K]>Fires when key is deleted

Methods

set(key: K, value: V): void (Server Only)
Sets a key-value pair.
map.set("key", "value");
get(key: K): V | undefined
Gets a value by key.
const value = map.get("key");
delete(key: K): boolean (Server Only)
Deletes a key.
map.delete("key");
has(key: K): boolean
Checks if key exists.
if (map.has("key")) {
    // Key exists
}

NetworkedSet

Replicated set.

Constructor

new NetworkedSet<T>(config?: NetworkVariableConfig)

Properties

PropertyTypeDescription
onItemAddedSignal<[T]>Fires when item is added
onItemDeletedSignal<[T]>Fires when item is deleted

Methods

add(item: T): void (Server Only)
Adds an item to the set.
set.add("item");
delete(item: T): boolean (Server Only)
Deletes an item from the set.
set.delete("item");
has(item: T): boolean
Checks if item exists in set.
if (set.has("item")) {
    // Item exists
}

RPC

Namespace for RPC decorator and configuration.

Decorator

@RPC.Method(config: RPC.Config)
Marks a method as a Remote Procedure Call.
@RPC.Method({
    endpoints: [RPC.Endpoint.CLIENT_TO_SERVER],
    accessPolicy: RPC.AccessPolicy.OWNER
})
public myRPC(): void {}

Configuration

interface RPC.Config {
    endpoints: RPC.Endpoint[];
    accessPolicy?: RPC.AccessPolicy;
    returnMode?: RPC.ReturnMode;
    reliability?: RPC.Reliability;
}

Enums

RPC.Endpoint
  • CLIENT_TO_SERVER - Client calls server
  • SERVER_TO_CLIENT - Server calls client
  • CLIENT_TO_CLIENT - Client calls client (not yet implemented)
  • CLIENT_LOCALLY - Client calls locally
  • SERVER_LOCALLY - Server calls locally
RPC.AccessPolicy
  • NONE / ANYONE - Anyone can call
  • OWNER - Only owner can call
  • NOT_OWNER - Only non-owners can call
RPC.ReturnMode
  • DOES_NOT_RETURN / VOID - No return value
  • RETURNS - Returns a value
RPC.Reliability
  • RELIABLE - Guaranteed delivery
  • UNRELIABLE - Fast but may be dropped

Scene Management

SceneManager

Manages game scenes.

Properties

PropertyTypeDescription
currentSceneScene | undefinedCurrently loaded scene
sceneChangedSignal<[Scene]>Fires when scene changes

Methods

static loadScene(scene: SceneSerialization.SceneDescription): Scene
Loads a scene.
SceneManager.loadScene(MyScene);
Parameters:
  • scene - Scene description
Returns: Loaded Scene instance
static unloadScene(): void
Unloads the current scene.
SceneManager.unloadScene();
static changeScene(scene: SceneSerialization.SceneDescription): void
Changes to a new scene (unloads current, loads new).
SceneManager.changeScene(NewScene);
Parameters:
  • scene - Scene description
static importScene(scene: SceneSerialization.SceneDescription): Scene
Imports a scene from description without loading.
const scene = SceneManager.importScene(MyScene);
Returns: Scene instance

Scene

Represents a game scene.

Properties

PropertyTypeDescription
descriptionSceneSerialization.SceneDescriptionScene description

Methods

startFromWorkspace(): void
Starts the scene from existing workspace instances.
scene.startFromWorkspace();

Utilities

Signal

Event system for type-safe callbacks.

Constructor

new Signal<T extends unknown[]>(name?: string)
Parameters:
  • name - Optional name for debugging

Methods

connect(callback: (...args: T) => void): Connection<T>
Connects a callback to the signal.
const conn = signal.connect((value) => {
    print(value);
});
Parameters:
  • callback - Function to call when signal fires
Returns: Connection object
fire(...args: T): void
Fires the signal with arguments.
signal.fire(42, "hello");
Parameters:
  • ...args - Arguments to pass to callbacks
destroy(): void
Destroys the signal and disconnects all connections.
signal.destroy();

Collector

Garbage collector for automatic resource cleanup.

Methods

add(item: RBXScriptConnection | Instance | (() => void) | { destroy(): void }): void
Adds an item to be cleaned up.
collector.add(connection);
collector.add(instance);
collector.add(() => print("cleanup"));
Parameters:
  • item - Connection, Instance, function, or object with destroy method
teardown(): void
Cleans up all added items.
collector.teardown();

Type Definitions

SceneSerialization.SceneDescription

interface SceneDescription {
    children: GameObjectDescription[];
}

SceneSerialization.GameObjectDescription

interface GameObjectDescription {
    name: string;
    transform?: SerializedTransform;
    components: ComponentDescription[];
    children: GameObjectDescription[];
}

SceneSerialization.ComponentDescription

interface ComponentDescription {
    path: ExportPathString; // ["folder", "file", "export"]
    data: Record<string, any>;
}

Configurations.GameConfiguration

interface GameConfiguration {
    startingScene: SceneSerialization.SceneDescription | string;
}

Next Steps


Complete API reference for building games with CORP! 📚