Should I use bindToClose when saving data? (PROFILE SERVICE)

  1. What do you want to achieve?
    Should I use bindtoClose to save data during shutdown? For profile service.
game:BindToClose(function()
    if game:GetService("RunService"):IsStudio() then return end
    if game:GetService("RunService"):IsRunMode()then return end
    if(game:GetService("Players") ~= nil) then
        for _,player in ipairs(game:GetService("Players"):GetChildren()) do
            dataSave(player)
            TeleportService:Teleport(PlaceId, player)
            wait(1)
        end
    end
end)
1 Like

the reason we use bind to close with regular data stores is that if its just 1 player in the server and they leave the data wont be saved when they leave as the server will be dead by the time they try and access it. You notice this easily when force shutting down in studio test (clicking the red square) making it not save without bind to close. remember all it does is it guarentees that this code will run when the game is getting shut down

2 Likes

Did you use bind to close with profile service?

No, you don’t need bindtoclose with profileservice. It autosaves!

1 Like