Before I say anymore, I want to mention I am fairly new to LUA and am still trying to get the basics down. I was originally working on this game with someone else, but he had to take a leave from the project to some Covid-19 complications. I figured I should continue trying to do what I can to help get the project out in a more efficient time.
The survival game begins with an opening scene of a place crashing. Everything is scripted and good to go but somethings don’t line up. We have one main module in StarterGui that is responsible for the audio and text. The rest of the scrips are in Explorer and are responsible for a screen shake effect, lights, and the motion of the plane diving. What I’ve come to notice is the two rarely match up. The audio has an initial bang where the lighting, screen shake, and diving motion are supposed to start, but they usually tend to be one second early or late.
I went back and tried to see if I could run the scripts from the main module in StarterGui, but that didn’t work. This brings me to my question, do you guys/girls have any advice or recommendations for the best way to align scripts at the beginning of a game so they all match up?
(The rest of the scripts located in explorer are in individual blocks that work as the lights)
whereas say Script A finished it’s animation
it could fire a BindableEvent or a RemoteEvent (depending on the usecase) so that Script B can continue it’s animation.
EDIT: Forgot you said you were new too lua (I gotta get some sleep)
Here are some resources to get started with Remote Event Bindable Event
Some of the issues that may cause delay in-game (not studio) are server script, if the user is lagging most if not all server scripts that you’ve put in the game would be delayed due to the user’s poor connection.
You might wanna use Local Scripts for certain stuff to avoid delaying these stuff, but keep in mind that local edits are also accessible by exploiters, so you wanna improve the game security and learn more on when to use a local script and a server script.
Reason server scripts are slow is because they take time to process from the client to the server.
This video will help you understand in detail what I’m talking about:
If there’s any reason that is causing a delay is probably because of the amount of wait() in your scripts.
Also make sure you aren’t using the spawn() function and instead use something like coroutine.wrap() as spawn will only run at the next task scheduler cycle, thus a delay could be experience in your script if they were all originally lined up.
My take on this: Don’t use multiple scripts for this.
As you state that this is an ‘opening scene’, I assume the player(s) cannot interact with anything, cannot move their character(s) around, and basically are just looking at a ‘cut scene’ being shown to them.
So to align / synchronize the audio and visuals, everything should be controlled client-side (per player) in a localscript, that have client-sided control of the lights, sounds, blocks[*] & camera … and “the scripted action” being shown.
[*] These blocks should be created client-sided for only “this player”, as in; cloned from ReplicatedFirst / ReplicatedStorage, and then be destroyed once the ‘cut scene’ has ended or is not needed anymore.
To synchronize that this ‘cut scene’ get started at the (approximately) same time for all players, the localscript should be coded in such a way, that it listens for a “GO”-signal being sent from the server. I.e. RemoteEvent, FireAllClients. - Then the server should wait at least 2-to-5 seconds longer, than what the ‘cut scene’ actually takes to play, to allow slower clients become ready too, before continuing.
The suggestion of using coroutine.wrap() (or fastSpawn?) instead of the regular spawn() method, I don’t think would help in any way, as the biggest ‘time skewing’ is due to something being “animated” server-side and something being “animated” client-side, where replication and network latency is the unknown factor.