RoClass

Events

Events is a core module in RoClass that provides an easy way to create and manage custom events on objects.
It allows connecting multiple listeners, firing events, and safely disconnecting them.


Table of Contents


Overview

The Events module provides a lightweight event system:

This system works for both RoClass objects and regular Roblox instances.


API

Event.new(): Event

Creates a new event object.

event:Connect(callback: (...any) -> ()): RBXScriptConnection

Connects a listener function to the event.

event:Disconnect(connection: RBXScriptConnection): nil

Disconnects a previously connected listener.

event:Fire(...: any): nil

Fires the event, executing all connected listeners.


Examples

Creating and connecting to an event

local Event = RoClass.Event
local MyEvent = Event.new()

local conn = MyEvent:Connect(function(msg)
    print("Event received:", msg)
end)

MyEvent:Fire("Hello") -- Output: "Event received: Hello"

Disconnecting a listener

MyEvent:Disconnect(conn)
MyEvent:Fire("Won't print") -- No output


This documentation is part of RoClass. For more examples and detailed guides, see RoClass Docs.