I have a script on the client that loops all the players in the workspace and requires their Data/Stats Module and sets their character stats accordingly. This loops every 0.1 second. Will this cause too much threads and lag if there where a 100 characters/players in the workspace?
When a module gets deleted does it automatically disconnect all threads?
Is it really necessary to do this every 0.1 seconds? I would have a guess that there is probably a better way to do what you are trying to achieve (but maybe not, just expand on why you need to it so frequently please).
1 Or 2 seconds would be plenty fine,
Then your dividing the lag by x10 or x20, it doesn’t need to be instant as ping is a thing anyway which for most is over 0.1 second
The best solution would be to run the event WHEN a user changes their data to make the game more optimized.
The approach you are using wastes a lot of processing resources because the program will try and update the player’s data even when there are no changes to the data (effectively updating nothing, and using up valuable procesing time). Having said this, computers are very powerful today and so I would estimate that there would probably be minimal drop in performance from running something like this. However, that doesn’t mean it’s not bad programming practice to do it this way (please don’t do it like this).
A better approach is to update the data for all clients only when the data changes. This way you do not need to be running a loop every 0.1 seconds.
As stated above, it’s more performant if you update only when the data changes.
To achieve that, I would suggest linking a RemoteEvent from the server to the client that is fired when data changes, and only provides the changed data to each client. The client should then have code that knows how to apply the data accordingly.
We can’t assume that they’re getting/setting anything to a DataStore based off of the information that we’ve been given. Furthermore, I would also counter your suggestion of writing player data to value objects such as NumberValues, StringValues, etc. as that will also waste more resources than necessary.
While the cache is a good idea, the cached data should be saved in a simple table within the script that is managing player data. That’s the most efficient way to store and manage it.