Search code examples
luaroblox

RemoteEvents in ReplicatedFirst do not fire OnClientEvent handlers


I'm trying to make a loading screen disappear when the server says that everything is ready, but the event listener in a LocalScript isn't firing when I would expect it to.

Inside a LocalScript in ReplicatedFirst, I have this :

print("Hello world - Local Script!", tick())
game.ReplicatedFirst.RemoteEvent.OnClientEvent:Connect(function()
    print("ReplicatedFirst event signal received!", tick())
end)

And inside a Script in ServerScripts, I have this :

print("Hello world! - Server", tick())
while true do
    print("Firing event from server...", tick())
    game.ReplicatedFirst.RemoteEvent:FireAllClients()
    wait(3.0)
end

And in the output I'm getting this :

  Hello world! - Server 1585699530.2938
  Firing event from server... 1585699530.2945
  Hello world - Local Script! 1585699531.4771
  Firing event from server... 1585699533.3019
  Firing event from server... 1585699536.3193
  Firing event from server... 1585699539.3349
  Firing event from server... 1585699542.3354

After each of the "Firing event from server ..." lines, I would have expected to see the message "ReplicatedFirst event signal received! (timestamp)".

The docs recommend that you use ReplicatedStorage :

In order for both the server and clients to utilize a remote event, the RemoteEvent object itself must be in a place where both sides can see it. As such, we recommend that you store the RemoteEvent inside of ReplicatedStorage, although in some cases it’s appropriate to store it in the workspace or inside a Tool.

but my assumption was that ReplicatedFirst was one of those shared locations. Is this not the case? Is ReplicatedFirst not a shared location? Or am I doing something simply wrong?


Solution

  • It turns out that ReplicatedFirst has some strange rules around client/server replication. It should be considered that the contents of ReplicatedFirst are owned by the server, and when a player joins, the contents are copied, not replicated, to the new player.

    But because each player has their own copy of the contents, trying to connect to RemoteEvents hosted in ReplicatedFirst will not throw any errors, but will not succeed either.