Datastore best practices

You do not have the correct code.

That is way outdated

This tutorial is decent and might help you improve and add more functionality such as session locking to your system:

I referenced the most recent version of the code you posted.

You have to look at the module, not the code i posted. You can find it here

Still would trigger the PlayerRemoving event which would overwrite their data. You need to check to see if the module loaded their data before updating it in the PlayerRemoving event.

If you’re sharing a public module I would leave kicking up to the developer.

This is fair. ProfileService and other modules like it usually just autosave every 30 seconds or so.

I don’t see that logic in any of the snippets you’ve posted. It simply calls saveData in the PlayerRemoving event, which is why I assumed it’s an issue.

EDIT: This reply is referencing the code snippet(s) you posted in this thread. If you want people to review your DataStore module you should post it in #help-and-feedback:code-review so people aren’t confused.

Why not just:

local Players = game:GetService("Players")
Players.PlayerRemoving:Connect(saveData)
game:BindToClose(function()
    for _, Player in ipairs(Players:GetPlayers()) do
        saveData(Player)
    end
end)

I fixed the issue regarding it saving the data even if its outdated.

I havent released it yet though since i am waiting to first add autosaving then release one big update.

That’s what I meant.
Additionally, you should make sure not to save the data twice when the server shuts down.

Please review the module to see the code

@asadefa my module had implemented this featue before you mentioned it.

Furthermore, its recommended by AI

Stop spreading this extremely misleading statement- AI is not a trustworthy source of information all it did was see your post appear in search results and summarize it. There was no deep analysis into the code or any sort of reasoning behind this showing up.

2 Likes