Race conditions

Hello, I’ve been working on a system that uses client input to trigger animations locally, alongside a separate system where client input is sent to the server for processing. The server performs calculations and then sends the results back to the client.

However, I’ve encountered a problem: the client-side animation system requires data from the server to function correctly. Since direct client input is always faster than the server-to-client round trip, the animation system doesn’t have the necessary data in time to proceed accurately. While the server’s response is relatively quick, it will always lag behind the local input system.

I’m looking for a solution to this issue. I want to avoid relying on client-side assumptions and prefer to use accurate, server-validated data.

Currently, I have a local script that, upon user input (e.g., a mouse click), retrieves attributes from a centralized local storage system. This setup allows other scripts to request and use these attributes dynamically. The challenge is that the necessary data from the server arrives too late for the local script to process it in time.

What would be the best approach to handle this problem?

You could request information from the server ahead of time. If you know about the ContentProvider, you could do something similar.

If the animations are handled dynamically and can’t be preloaded, you could give the player the resources to calculate the animation themselves.

Or, you could be using server scripts to play the animations, then yes it’s going to be lagging behind a bit, so you can learn to work with modules and localscripts.

2 Likes

Thanks for your reply,

I’ve looked into the ContentProvider, but it doesn’t seem to fit well with the system I’m working on. Since the attributes in my system are dynamic and rely on server-side calculations, the values are not static. This makes preloading impractical as they change in real time based on client input and server processing.

Your second suggestion — allowing the client to calculate animations locally — seems much more applicable to my case. However, I’m concerned about desynchronization. If the client uses its own calculations for animations, there’s the possibility that, over time, the client’s state will run ahead of the server’s authoritative state. This could lead to setbacks when the server has to reconcile mismatches in input and state.

As for using server scripts to play animations, I understand the lag that comes. While it’s less responsive, I agree that using modules and LocalScripts to handle animations client-side can improve responsiveness.

1 Like

You could try making the server and client update at fixed times (ex: every 500ms). It would make it synchronized but would have a delay.

Also I think this concept might be useful: Reconciliation with Correction

Remote functions already yield the script until the data is received (ie. your local script will not run until server-side sends that data back). So I’m thinking this should work:

local data = getServerData:InvokeServer()
playAnimation(data) -- Doesn't run till data gets a return

Unless I’m missing something, which, judging from the other 2 responders, I am.

1 Like