![empress closed game save data empress closed game save data](http://www.savegameworld.com/wp-content/uploads/2021/07/PC-Resident-Evil-Village-SaveGame.jpg)
Which I guess would work, as it stalls the close, but I don’t recommend just yielding. I’ve also seen some scripts where they wait() (or yield in some form) in the function, presumably because the writer thinks it buys them more time. So what happens when we apply this knowledge into our code? game:BindToClose(function()Īnd just like that, the data should properly be saved. GlobalDataStore:SetAsync), it takes indeterminate time to finish, and when you call them, they yield the current thread until the request is completed, and selects a thread that Roblox manages to resume When you use a function that is labelled with Async (e.g.
Empress closed game save data code#
A coroutine can also “yield” (pause) to pause through its code and give control back to whatever resumed it.Īnd that’s all you really need. Coroutines can be “resumed” by in another coroutine. They aren’t truly running in parallel, but it seems like they do by switching flawlessly between each other when you yield. If you’re unfamiliar with multithreading, only a single thread (“coroutine”) can execute at a given time. This probably won’t make sense right now but I’ll explain soon.
![empress closed game save data empress closed game save data](https://images.pond5.com/beautiful-empress-tarot-deck-close-footage-122002718_iconl.jpeg)
This time should be used to save other players’ data as well. There’s that possibility it can go over that 30 second cap, which means the remaining players’ data wouldn’t be saved. It then makes another one, resulting in a waste of time.
![empress closed game save data empress closed game save data](https://media.moddb.com/cache/images/downloads/1/176/175930/thumb_620x2000/Uten_navn.png)
What’s going on in that code is, it makes a web request, then waits for its completion. The issue with this code is it saves data asynchronously rather than synchronously. Unfortunately I don’t believe we can accelerate the speed that Roblox picks up our requests. And Roblox wants 700+ player servers apparently. In my experience a web request took about 1/2 to 1 second to complete. This can get even more troublesome if your game can have many players. Yes, since data store requests are web requests, they can take a long time depending on the responsiveness speed of the Roblox servers and other factors. This probably wouldn’t be an issue if data store requests didn’t take indeterminate time to complete. When those 30 seconds are over, the server shuts down regardless of if they’re done. Roblox only allows 30 seconds for all the bound functions to execute. Remember that I said there’s a catch? Here’s the catch: In addition to data saving when the player leaves, it also saves the remaining players’ data when the server shuts down. game:BindToClose(function()įor _, player in ipairs(Players:GetPlayers()) doĪnd there it is. Multiple functions can be bound, and they’ll all be called in a separate thread when the server shuts down. This can be done via the DataModel:BindToClose method, which takes a function as an argument, and is called when the server shuts down. In addition to saving upon a player’s removal, also save when the server shuts down. In these cases, the PlayerRemoving event listener is never called or doesn’t finish. A network error is encountered and the server therefore is forced to shut down.A developer manually shut it down via the game page.The 3 ways that come to mind are these (do give me more if there are): When a server is in the process of shutting down, its priority is shutting down and stops doing anything else. You might be thinking that this alone is fine. They join, you load their data, they leave, save that data. Players.PlayerRemoving:Connect(function(player: Player) Players.PlayerAdded:Connect(function(player: Player) Local cash_data_store = DataStoreService:GetDataStore("CashDataStore") Local Players, DataStoreService = game:GetService("Players"), game:GetService("DataStoreService") But why is this? What’s going on?įirst off, some data loading and saving scripts look kind of like this - in this very specific example it's saving cash If that’s you, you’re in the right place. Your script that saves data doesn’t seem to work.