In my game World Builder, I have a system which allows players to create mechanisms that can range from simple things to complex things, however recently players have been encountering issues where complex systems that turn things on/off quickly can very quickly lag players in the game to the point where it becomes unplayable for them.
I determined that the cause of the lag issues was due to the design of the system, which unfortunately cannot be avoided as I need to store information about the state of the block so that the game can accurately load the block in with it’s same state, and the mechanisms that trigger a block to be powered on or off cause lag due to the server trying to replicate too many property changes at once to the players (it uses a boolean value to track whether the block is activated or not).
What are some possible solutions I could try for this system? Personally it would’ve been nice if Roblox had a feature to throttle or limit the amount of property changes that could be replicated each second but that unfortunately doesn’t exist.
That’s not the issue I am trying to overcome here, the issue is that the system has to use BoolValues to represent what state the block is in (Powered, activated, etc) due to the way world saving works (I make use of CreatePlaceAsync and SavePlaceAsync), but when there are complex mechanisms built by players present, it can get laggy due to the server replicating far too many property changes on the boolvalues when the state changes.
I am trying to find out if there is a way I can get around this issue as it is devastating for players in my game who want to make cool mechanisms.
I already store the state of them in a table for each block on the server, the values are mainly so that when the server loads again the next time after all players leave it will properly load the blocks in its correct state
The easiest solution would be to optimize your loops, and reduce your O(n) time. However, that might not be what’s causing the lag. You could try optimizing how you update the state of parts, one thing I think the issue could be is that once a part has its status updated, all the nearby parts update as well and the cycle repeats (assuming thats how your system works). Optimizing this process will probably be the best solution.
Unfortunately the issue isn’t the loops, they work perfectly fine, the issue is that Roblox is trying to replicate too many property changes to the player’s client at once which is resulting in the game gradually or quickly becoming laggy as the network gets held up trying to replicate these changes, I might actually try only updating the representation of a block’s state at specific intervals instead of immediately however
Maybe try updating the client less rapidly by including more updates per firing of the client event? Not too familiar on how client/server events specifically work and how they cause lag, but in theory by reducing the rate at which they need to be sent should reduce lag
It’s not an event I am firing, as I’ve said before what I am doing is changing a BoolValue’s value property, and Roblox’s engine replicates the property change, which it seems they have no limitation on how fast or how many can replicate each second