So i have a script that subscribes to and sends out a value data for an intvalue in my game every time it’s changed. My plan is to have this intvalue be the same in every server and to have it update to all servers every time it changes in one server. Pretty sure this works, however, if there are no servers then the value just resets to the default so I figured I needed a datastore for it when a server closes but I’m not sure how I would go about saving a server value instead of saving it with players like normal.
This is the script for the messaging service I have to update the SizeValue of a ball among all servers. But like mentioned before, if there are no servers then it just defaults back to its starting point since obviously there is nothing to send data between.
Use game:BindToClose() that fires during server shutdown(when the last player leaves). After that event fires you have 30 seconds to save the ball data to the datastore. Saving server data in datastores is easy, just use a custom key instead of a user id, for example the key "ball".
If you have multiple servers running frequently, I would suggest only saving to the datastore if another server hasn’t done it for the same ball state, and only if you can guarantee that server has the latest version(so you don’t accidently reset the state back to an old one).
forgot about that function tbh, but even when I’m using it here it seems to not work weirdly? The save after 30 seconds works properly and loads it when I start another server but if I stop the server before the 30 seconds the bindtoclose doesn’t save the data. I have this script for the saving