RemoteEvent Events Stack Before OnServerEvent Is Called

I am having a little problem with RemoteEvents. I set up the scripts so that the client can call an event to the RemoteEvent before the server actually connects to the RemoteEvent (.OnServerEvent:Connect(function()). I assumed that the server wouldn’t start receiving events until it was connected, but what happens is any client events called before the server connects all happen at once when it does connect. I don’t want those events that were called before the server connected, so I’m wondering if there is a way to identify if an event is called before the server connects or not (like a timestamp or something).

Example code:
(Client)

for i = 1, 30 do
	game.ReplicatedStorage.RemoteEvent:FireServer("example")
	print("called")
end

(Server)

wait(5)

print("connected")
game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(plr, event, part)
	print(event)
end)

(Output)

  20:49:36.257   ▶ called (x30)  -  Client - LocalScript:3
  20:49:40.519  connected  -  Server - Script:3
  20:49:40.519   ▶ example (x30)  -  Server - Script:5
1 Like

Are you referring to it being called 30 times all at once


If so, you need to add a wait() “preferably task.wait() as it is more consistent,” with a time increment of anything over 5 seconds for example. (I’d recommend making it anywhere from 1 second to 50 seconds)


If this isn’t the case, can you provide more detail on what you are having troubles with?

My problem isn’t really how it’s called, since if it all calls before the server connects then the server will process them all at once (this means that no matter how big of an increment there is, as long as they are called before the server, then when the server does connect it will think they were all called at once). I’m trying to figure out how to identify calls that have been made before the server even connects to the RemoteEvent.

1 Like

I reproduced this in a test game, but I’m confused on why this is an issue?

Remote events have a queue behavior which is expected.

If you do not want the queue behavior unfortunately there isn’t any API to control this queue, just connect the RE and drop the function when not enabled.

Not sure why you need this behavior there might be other better alternatives but here are the methods I can think of atm.

bool method

local RE_Enabled = false
game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(plr, event, part)
if not RE_Enabled  then
return
end
	print(event)
end)

wait(5)
RE_Enabled = true
print("enabled")

Or time stamp

local RE_Enable_TimeStamp = os.time()+5
game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(plr, event, part)
if os.time() > RE_Enable_TimeStamp  then
return
end
	print(event)
end)

3 Likes

This solves my problem, too bad I can’t record when the actual RemoteEvent receives the event for how I set up the OnServerEvent.