Good morning, Roblox Developer Forum! I’m currently attempting to make an election voting poll (for a fiction game I am an administrator in), and I am having trouble thinking of an efficient method to save data.
Right now, this is a step-to-step system of how I want my code to work:
Player votes on a nominee via. a TextButton
LocalScript recognizes MouseButton1Click, fires a remote
Script recognizing the FireServer, retrieves the data of how many votes the nominee selected has, and adds 1 to the data (will always be a number)
Script then saves the data
I originally chose to use DataStoreService, however, someone in the server mentioned that when the server receives a high amount of requests at once, ROBLOX will deny some of them. This being said, does anyone have any good ideas to efficiently save data?
You can cache the data instead of writing to the datastore everytime. When the game loads, you can load all the nominees into a dictionary with the value of 0. Then, whenever a user votes, add 1 vote to the nominee’s value. You could then periodically save the data, adding the value from inside the dictionary into the datastore and using :UpdateAsync to update the data within the datastore, you should then set the nominee’s dictionary back to 0. You should also use :BindToClose() for when the game is closing, and save the data into the datastore there.
I don’t see a point in saving the data periodically, the person can only vote once, and when they voted, they will be kicked. What is the difference between this and my failed strategy?
Do you mean saving the nominee’s data all through 1 variable? I am trying to save this data to some form of database (DataStoreService, even Mongoose if I can’t find any other viable option).
But saving to a datastore is global, through the whole game and not just the server. I think ROBLOX has a cooldown system on this, not to say it isn’t lenient, but still.
I checked this page, it says DataStoreService doesn’t necessarily decline the requests, however just throttles the server, delaying the time for it to finally upload.
After doing some digging around, I have decided to just use DataStoreService. I believe ROBLOX doesn’t throttle many requests from different servers, so I think it’ll be okay.