Is there a limit to how many times I can connect to one signal?

I’ve come to realise that I’ve been handling resetting systems wrong (as in, interfaces/systems/so on that should reset when the character dies or is respawned). I now know that I should do them individually for each system rather than trying to stuff them into a single handler.

I do have some experiences that may vary on the number of systems that should be reset when a player dies though… so that might result in having a pretty nasty amount of connections to Died or CharacterAdded/Removing. The cost of the RBXScriptConnection shouldn’t matter though.

Thing is - is there a limit to how many connections I can make? I let a piece of code run for a few seconds and it seems to suggest no (it over 1000) but there might be a limit I’m unaware of or some bad implications about having a lot of connections. I’ve previously given advice regarding mass amounts of connections but sometimes I get unsure of my own answers.

local conns = 0
while true do
    workspace.Changed:Connect(function () end)
    conns += 1
    print(conns)
    task.wait()
end

I don’t think there’d be a difference if I decided to make one central connection and a subscriber module that executes all the functions I want to occur but even in Deferred this sounds pretty bad.

Roblox tends to have a lot of hidden engine quirks or unknown ways to optimise experiences (some of which I forget because of how obscure and uncommonly used they are), so… blanking on this one.

As far as I know, there’s no unknown limit to the number of connections you can have to an event. The code that is run is asynchronous, so that when the event fires, the functions tied to those events are all called through interrupts, which is done by hardware. I don’t know the intricacies of Roblox’s engine, but that’s the way most computing is done (to my knowledge).

1 Like

there is no limit other than the hardware’s own memory. on the client side we have that of course, but on the server side i don’t remember roblox giving a limit. of course there is one but i guess it’s high enough.
another limit is the length of a step. if you create too many connections, and in general, too many threads, they will tend to lag,
it also matters how intensive each connection or thread is, in this case, even if they are few, they will still cause lag.

You can create many threads, but it is best not to create them at the same time.

Oh yeah, I had another topic related to how the events are called, to which an engineer responded for: Do connected functions run relatively at the same time?

I know that Deferred mode would heavily reduce the cost/expense to run these over Immediate because of its queueing behaviour. It would just suck if I suddenly found out some day that there’s an arbitrary limitation and I have to rearchitecture any deep code I may write with them. The project I have in mind is intended to be lightweight without a deep framework to it.

1 Like

I don’t believe there’s a hardware limit to how many connections you can make but having a large amount of them will obviously cause performance issues.