I’ve been trying to figure out, how can i sync the client with the server using only time. So if both server and client have a part, and they move from point a to point b, how can we get the client to sync with the server’s part, but using only os.time.
I previously tried doing this, receving the servers time through a remote event, getting the clients time and deducting the recevied servers time but no luck.
Only time is to be used, not constantly sending positions.
Sounds like you’re trying to do some kind of prediction.
Elaborate what this is for perhaps?
Now let me make one thing clear.
It is practically impossible to perfectly sync up the client and server, your internet connection likely has to go over seas or across the ocean so there will always be a bit of delay or desync that you will simply have to live with.
However,
really one of the best ways to go about it is to just predict the future with what information you have which let’s you decrease how much it’s desynced.
But you’ll never have 1:1 synced parts, just remember that, simply not possible.
Now instead of os.time() you may wanna use elapsedTime or tick() instead.
os.time() only gives you the passed time in seconds, you need higher precision than that.
On the server, store tick() or elapsedTime in a variable and fire a remote event to the client.
Wait for the client to send a remote event back.
Compare the time you stored with the current time (tick or elapsedTime), this is how long it took for the signal to go back and forth.
This single number you can simply multiply with nearly anything to get a rough prediction or estimation of where a moving object could be in the next second.
Say you have a paintball gun that shoots a ball of paint, to compensate for lag, we teleport the bullet a little ahead of the gun, the distance ahead would be based on that time I mentioned.
Although things will never be 1:1, close enough isn’t what i’m getting.
I tried to factor in ping and such before but it didn’t help.
I made a post about this yesterday.
I fully understand something at anypoint can go wrong with the clients connection, resulting in a desync, but you’d think it’d work just for a little, but it doesn’t.
My only reason is maybe due to how the server is firing first, i’m not entirely sure.
I’m thinking of making a some-what tower defence like game. I simply want to network the speed of the enemies and their starting point. That should be enough for the client to simulate where the enemies should be. Now of course we would verify everything serverside.
I’m still just trying to find a method of syncing a client part to a servers part using speed, start position and direction.