Detect when a new listener "function" is added

I am making a simple API which allows scripts to interact privately with each other.
Right now, I am trying to figure out if you could detect when a RBXScriptSignal:Connect() has been fired. Not the function.

Example of what I mean.

game:GetService("RunService").Heartbeat -- RBXScriptSignal
----------------------------------------------------------------
game:GetService("RunService").Heartbeat:connect(function() -- The function.
end)

What prevents me from making this is that I need to detect when that has been fired to prevent unauthorized access to the event. You may ask “Why don’t you just make the ‘event’ like imaginary, like they are actually communicating privately?” and here’s my answer: I want it to be compatible with every script, and make it so if unauthorized scripts try to access it, it needs permission from the script that made the event.


Suggestions, Questions and answers are appreciated.


EDIT: There was a post like this ‘Is there a way to get all events connected to an object’ but it doesn’t solve my issue and was not helpful at all.

I dont think you can detect listener in script as some may made in client some might be script and scripts dont have the power to read other script except for module

1 Like

Specifically, I am using a modulescript. Not a script.
You can read contents in a script from a modulescript, but it is extremely complicated and roblox limits most features, which allows you to only see globalized functions(a function in which it’s not localized.)

I don’t use this though because you’re not creating a whole new function for the event, but you also don’t know if they are.
And you can’t detect if the function is getting added yet.

Also, i’m pretty sure exploits can only do it, not client. Client can’t do it normally, but exploits can because roblox limits most features as I said before.

You can’t do that on services, like RunService. But if you made a wrapper for it, you could override the :Connect() methods and fire signals internally. That’s what I would do.

1 Like

Well, thinking logically, they wouldn’t allow us to make a wrapper for it anyways, because most of Roblox’s services are locked by metatables, so that way is no good.

Something like this:

local RunService = game:GetService("RunService")

local RunServiceWrapper = {}
    
function RunServiceWrapper:BindToRenderStepped(name, callback)
    -- Pretend this is a signal or bindable event
    RunServiceWrapper.RenderSteppedBound:Fire()

    RunService:BindToRenderStep(name, Enum.RenderPriority.Last, callback)
end

function RunServiceWrapper:UnbindFromRenderStepped(name)
    -- Pretend this is a signal or bindable event
    RunServiceWrapper.RenderSteppedUnbound:Fire()

    RunService:UnbindFromRenderStep(name)
end

return RunServiceWrapper
1 Like

That could work, however I try to minimalize the amount of steps needed just to get a simple API working.

Yeah I mean this would be the same as just referencing RunService:BindToRenderStep(). But I think in this case it’s worth it to require the extra module, because of the features you can add.

Realistically you’d be requiring this module in place of RunService, so it’s basically the same thing. Wrappers are very powerful and should be used frequently.

1 Like

You are correct.
I guess it wouldn’t hurt to add another module, thanks for helping. I will mark your comment as the solution after I get the extra module working.

1 Like