Skip to content

No Events In Events Callback

ErrorRoblox
small-rules/no-events-in-events-callback

Disallow sending Events back to the same player inside an Events.connect callback; use Functions for request/response.

Rationale

Sending an Event back to the same player from inside its own .connect callback is a footgun. You’ll get recursion or just confuse the request/response flow. Use a Functions callback for that. It’s the right tool.

This tracks which players you’re sending Events to inside a callback and yells if you call Events for them again from within. You point it at your Events import with eventsImportPaths. It doesn’t guess.

Diagnostic Messages

preferFunctions
Do not call Events for the same player inside an Events.connect callback. Use a Functions callback instead.

Configuration

This rule accepts one options object after the severity.

eventsImportPathsRequired

Import paths that identify Events objects whose callbacks should be checked.

{
"jsPlugins": [
"@pobammer-ts/small-rules"
],
"rules": {
"small-rules/no-events-in-events-callback": [
"error",
{
"eventsImportPaths": [
"server/networking"
]
}
]
}
}

Examples

event fired inside callback
import { Events } from "server/networking";
Events.units.unequipUnit.connect((player: Player, unitKey: string): void => {
if (unitKey.size() > 0) {
Events.promptNotification.fire(player, "error");
}
});
event callback without configured import
import { Events } from "server/networking";
Events.units.unequipUnit.connect((player: Player): void => {
Events.promptNotification.fire(player, "error");
});