I created "Signal" Module with Autofield like RBXScriptSignal for Easy Integration in Roblox Projects + Validate Types Feature

Signals are a powerful tool in Roblox development for managing custom events and communication between different parts of your game. They allow scripts to trigger specific actions without tightly coupling components, making your code more modular and easier to maintain.

This Signal Module introduces four flexible signal types designed to fit various needs:

  • BindableSignal: Ideal for reacting to property changes with a binding function.
  • ReadableSignal: Extends BindableSignal by allowing data retrieval when the signal is fired.
  • Signal: A standard signal with basic event handling and firing capabilities.
  • SimpleSignal: A lightweight signal with essential features, including destruction support.

Example use

:hammer: Detailed API Reference

BindableSignal

  • Returns: BindableSignal, Bind (Trigger the signal.), Destroy (Destroy the signal and disconnect all connections.), DisconnectAll (Disconnects all active connections from the signal.)
  • API:
    • Connect: Connect a function.
    • Once: Connect a function that runs only once.
    • HasConnections: Check for active connections.
    • Wait: Wait for signal to be fired.

ReadableSignal

  • Returns: ReadableSignal, Bind (Trigger the signal.), Destroy (Destroy the signal and disconnect all connections.), DisconnectAll (Disconnects all active connections from the signal.)
  • API:
    • Connect: Connect a function.
    • Once: Connect a function that runs only once.
    • HasConnections: Check for active connections.
    • Wait: Wait for signal to be fired.
    • Get: Retrieve the data passed when fired.

Signal

  • Returns: Signal, Destroy (Destroy the signal and disconnect all connections.), DisconnectAll (Disconnects all active connections from the signal.)
  • API:
    • Connect: Connect a function.
    • Once: Connect a function that runs only once.
    • HasConnections: Check for active connections.
    • Wait: Wait for signal to be fired.
    • Fire: Trigger the signal.

SimpleSignal

  • Return: Signal
  • API:
    • Connect: Connect a function.
    • Once: Connect a function that runs only once.
    • HasConnections: Check for active connections.
    • Wait: Wait for signal to be fired.
    • DisconnectAll: Disconnects all active connections from the signal.
    • Fire: Trigger the signal.
    • Destroy: Destroy the signal and disconnect all connections.

You can get latest signal here

4 Likes

I don’t want to shoot you down or anything, but this isn’t exactly how you would add typing to Signals…

Example: Signal | RbxUtil

Sleitnick’s implementation of a signal has full intellisense using generic types.

Whenever it can’t be automatically inferred by the type system, you have to manually type it (basically when you use OOP) Like this:

{
    TestSignal: Signal.Signal<string, number>
}

I see this module has some other features than just a generic signal, so it’s definitely not useless by any means

1 Like

I also have another version that is based on Sleitnick’s Signal implementation. Would you be interested in seeing it? I plan to share it later, so I can provide it now if you’d like to take a look.

Sure, I can take a look at it when I get home

1 Like

– i understand now what you meaning im making new module wait for it
But hold on, I think my Signal can achieve that as well. You can try using this approach:

local TestSignal = Signal.createBindableSignal(function(property: string) end, '')

export type Some = {
    TestSignal = typeof(TestSignal)
}

This method maintains type safety and works similarly to Sleitnick’s signal system, but with stronger typing. It may be a little more complex than Sleitnick’s approach

Apologies if I misunderstood what you were referring to.

Anyway, I will release another version later that is based on the RbxUtil Signal.

Do you think making Signal.Connect() work without : and calling it directly like Signal.Connect() is a good idea? Or would it be better to stick with :?

because i found problem if i still use : to make auto field

1 Like

I would stick to using : if you didn’t, that would mean storing references to the actual reference somewhere else. I think that’d also be slower because metatable are optimized for things like OOP.

You’d should try rebuilding your module but without requiring and empty anonymous function for the typing (I assume that’s what it’s for)

Now everything is almost done

local Signal = require(script.Parent.Signal)

export type Some = {
     TestSignal : Signal.SimpleSignal<(property: string) -> (), string>
}

Is this what you want?

I have released a new version. Enjoy~~

Well the generics are supposed to be what the signal takes into fire and returns from connect

1 Like