Skip to main content

Overview

The SkyTeam ROBLOX module allows alliance member airlines to integrate the SkyTeam system directly into their ROBLOX games. The module handles API communication, player authentication, and real-time UI updates.

Module Architecture

The module is built in TypeScript using roblox-ts:
apps/models/src/module/index.ts
export interface Settings {
  /**
   * @interface Settings
   * @description This interface is used to define the settings for the SkyTeam module.
   *
   * @property {string} TOKEN - The token for the module.
   * @property {string[]} Flags - The flags for the module.
   */

  TOKEN: string;
  Flags: string[];
}

export default class {
  private Settings: Settings;
  public API: string = "http://localhost:4000";
  public RemoteEvent: RemoteEvent = new Instance("RemoteEvent");
  public Slocked: boolean = false;
  public InitalizationError: string | undefined;

  constructor(Settings: Settings) {
    script.Parent = ReplicatedStorage;
    this.Settings = Settings;
  }
}

Server-Side Module

The module runs on the server and manages client-server communication via RemoteEvents.

Initialization

The module initializes when the game starts:
apps/models/src/module/index.ts
public Initialize(): void {
  this.RemoteEvent.Name = ".SKYTEAM_CLIENT_RUNTIME";
  this.RemoteEvent.Parent = ReplicatedStorage;

  for (const Player of Players.GetPlayers()) {
    const ClientScript = script.WaitForChild("client").Clone();
    ClientScript.Parent = Player.WaitForChild("PlayerGui");
  }

  Players.PlayerAdded.Connect((Player) => {
    const ClientScript = script.WaitForChild("client").Clone();
    ClientScript.Parent = Player.WaitForChild("PlayerGui");

    if (this.InitalizationError) {
      this.PublicError("SERVER_INIT_ERROR", {
        Body: this.InitalizationError,
      });
    }
  });

  this.TestServices().catch((err) => {
    warn(err);
    this.InitalizationError = err;
    this.PublicError("SERVER_INIT_ERROR", {
      Body: `SkyTeam module failed to initialize. Please contact a developer. Error: ${err}`,
    });
  });
}
1

Create RemoteEvent

Sets up communication channel between server and clients
2

Deploy Client Scripts

Clones client script to each player’s PlayerGui
3

Handle New Players

Automatically sets up module for players who join mid-game
4

Test Services

Validates that HttpService is enabled and working

Service Validation

The module tests if required services are available:
apps/models/src/module/index.ts
private async TestServices(): Promise<any> {
  return new Promise(async (resolve, reject) => {
    const [success, result] = pcall(() => {
      HttpService.GetAsync("https://example.com/");
    });

    if (!success) {
      reject(result);
      return;
    }

    resolve(result);
  });
}

HttpService Required

The module requires HttpService to be enabled in game settings for API communication.

Error Handling

The module broadcasts errors to all clients:
apps/models/src/module/index.ts
private async PublicError<T extends EventTypeKeys>(
  WhichEvent: T,
  args: EventTypes[T],
) {
  this.RemoteEvent.FireAllClients(WhichEvent, args);
}
Clients receive error notifications and can display them to players:
apps/models/src/module/client/ErrorMessage.tsx
import React from "@rbxts/react";

export default function ErrorMessage() {
  return (
    <textlabel
      Text="An error occurred"
      TextColor3={Color3.fromRGB(255, 0, 0)}
      Size={new UDim2(1, 0, 0, 50)}
    />
  );
}

Client Integration

The client-side code connects to the RemoteEvent:
apps/models/src/module/client/index.client.tsx
import { ReplicatedStorage } from "@rbxts/services";

const remoteEvent = ReplicatedStorage.WaitForChild(
  ".SKYTEAM_CLIENT_RUNTIME",
) as RemoteEvent;

remoteEvent.OnClientEvent.Connect((eventType, data) => {
  // Handle events from server
  if (eventType === "SERVER_INIT_ERROR") {
    // Display error to player
  }
});

Communication Types

The module uses typed events for communication:
apps/models/src/module/shared/CommunicationTypes.d.ts
export type EventTypes = {
  SERVER_INIT_ERROR: {
    Body: string;
  };
  // Add more event types as needed
};

export type EventTypeKeys = keyof EventTypes;

Type Safety

TypeScript ensures type-safe communication between server and clients.

Example Implementation

Here’s how to use the module in your game:
apps/models/src/loader/main.server.ts
import SkyTeamModule from "module";

const SkyTeam = new SkyTeamModule({
  TOKEN: "YAY",
  Flags: ["flag1", "flag2"],
}).Initialize();

Configuration

TOKEN

Your airline’s API authentication token

Flags

Optional feature flags for the module

API Communication

The module communicates with the SkyTeam API:
public API: string = "http://localhost:4000";

Production API

In production, this should point to https://api.skyteam.dev

Module Structure

apps/models/
├── src/
│   ├── loader/
│   │   └── main.server.ts       # Example implementation
│   └── module/
│       ├── index.ts              # Main module class
│       ├── client/
│       │   ├── index.client.tsx  # Client-side handler
│       │   └── ErrorMessage.tsx  # Error UI component
│       └── shared/
│           └── CommunicationTypes.d.ts  # Type definitions

Features

Auto-Setup

Automatically initializes for all players, including mid-game joins

Error Reporting

Clear error messages when initialization fails

Type Safety

TypeScript ensures correct usage at compile-time

Client-Server Sync

RemoteEvents keep clients in sync with server state

Requirements

1

Enable HttpService

Go to Game Settings → Security → Enable HTTP Requests
2

Get API Token

Obtain your airline’s authentication token from the admin panel
3

Install Module

Add the SkyTeam module to your game’s ServerScriptService
4

Configure Settings

Set your TOKEN and any desired Flags
5

Initialize

Call .Initialize() to start the module

Best Practices

Secure Tokens

Keep your API token secure and never expose it in client-side code

Handle Errors

Always check for initialization errors and display them to players

Test Locally

Use the local API endpoint during development

Monitor Players

Track player joins and ensure they receive the client script

Troubleshooting

HttpService Not Enabled

If you see “HttpService is not allowed” errors:
  1. Go to Game Settings in ROBLOX Studio
  2. Navigate to Security
  3. Enable “Allow HTTP Requests”
  4. Restart your game

Client Script Not Loading

If players don’t see the UI:
  1. Check that the client script exists in the module
  2. Verify it’s being cloned to PlayerGui
  3. Look for errors in the Output window

API Connection Failed

If the module can’t connect to the API:
  1. Verify your API token is correct
  2. Check that the API endpoint is accessible
  3. Ensure HttpService is enabled

Next Steps

API Authentication

Learn how to authenticate API requests from your ROBLOX game

Build docs developers (and LLMs) love