Does constant event firing cause stress?

If I have a code like this:

RemoteEvent.OnServerEvent:Connect(MyFunction)

And it gets constantly fired, will the script listening get stressed out or cause server lag in any way? (The script will run for a long duration)

Note: I am aware that if a RemoteEvent gets fired multiple times, it will get stressed, however I would like to know if the same applies for scripts.

It wouldn’t cause server lag since the function would run on the client instead of the server, but it will take some cpu to call the function, but again just on the client.

1 Like

The code runs on the server since it uses OnServerEvent not OnClientEvent

1 Like

Yeah, I figured. My point applies to that circumstance specifically.

1 Like

I tried firing a RemoteFunction through:

while true do
    remoteFunction:InvokeServer()
end

Does not seem to lag.

1 Like

We can’t answer this without knowing the contents of MyFunction.

If the listener itself uses a lot of processing power then, yes, stress on the server will noticeably increase with more firing—the fact that the function is being used as a listener doesn’t necessarily impact this, though. Calling a not-so-performant function a lot in any context will cause performance issues.

On the other hand, if the listener doesn’t do much, you won’t have any issues.

6 Likes

Here’s the script

local function OnServerEvent(Client, Data)
    for i,v in ipairs(Players:GetChildren()) do
        if v ~= Client then
            RouterFolder[Client.UserId]:FireClient(v, Data)
        end
    end
end

for i,v in ipairs(RouterFolder:GetChildren()) do
    v.OnServerEvent:Connect(OnServerEvent)
end

(I’m currently working on the authentication of the data and some sort of delay)

The function itself is fine performance-wise, but firing every client when one client fires a remote and passing whatever the original client gave you to the other clients could cause some latency issues if abused.

A malicious user could repeatedly fire the remote with a large piece of data each time, and have every client sent the same large piece of data to them. This will take up a lot of bandwidth.

2 Likes

RemoteEvents will queue up.

But also remember that network frequency is less than framerate. In other words, it’s kinda pointless to call a RemoteEvent every frame. If I have to constantly fire RemoteEvents, I usually do it at a frequency of once per 0.1 seconds (10 a second), since a 100ms ping is probably pretty common among most users.

That being said, you could also get fancy and try to measure the latency and then adjust the delay based on that—but that’s kinda overkill, since it will just queue automatically for you.

6 Likes