Take a typical game loop with an intermission as an example. Players join and are waiting in an intermission area until a timer expires, after which there are several things that should happen on the client and server before the game starts.
The timer would be stored on the Server, so I have something like this in a Server script:
TimerFinishedEvent:Connect(function()
-- [Client] Fade screen out for all players
-- *** wait for fade out to complete before moving on ***
-- [Server] Move all players in intermission to game
-- [Client] Change camera for all players to camera setting for game
-- [Server] Run some code to initialize a new game
-- [Client] Load UI for the new game for all players (under fade gui)
-- *** wait for above to complete before moving on ***
-- [Client] Fade screen in for all players
-- *** wait for fade in to complete before moving on ***
-- [Server] Start game
end)
My question is: how can I properly wait for Client functions to finish if the functionality above is being called from the Server? I understand that calling a server-client-server sequence is potentially game breaking as the server should never wait for the client. But, if I’m firing RemoteEvents for the client actions above, there’s no way to tell on the server when they have completed.
I’ve considered adding generous wait()
's on the server such that client functions should finish by then, but I’ve read that wait()
in general should be avoided / this isn’t good practice. How can I accomplish the above otherwise? Or is there some way to reorganize this such that I can avoid the need to wait for Client functions to finish altogether?