I have a quick question regarding BingToClose
. Would both Options [1 and 2] below attempt to wait until all data is saved before closing down?? Or would it only be the case of Option 2.
The problem with Option 2 is that the forward declaration “save” remains = nil, so error.
- Is there a way to fix that?
- How can I synchronously save the players’ data?
Could it then be as simple as Option 3… Should I just let it go with the flow?
- Would I then risk some data failing to save in time?
DataService:saveData(Player)
returns a BindableEvent.
Option 1
game:BindToClose(function()
local save;
print("save from close")
for _,Player in pairs(game.Players:GetPlayers()) do
spawn(function()
save = DataService:saveData(Player)
save:Fire()
save.Event:Wait()
end)
end
return;
end)
Option 2
game:BindToClose(function()
local save;
print("save from close")
for _,Player in pairs(game.Players:GetPlayers()) do
spawn(function()
save = DataService:saveData(Player)
save:Fire()
end)
end
save.Event:Wait()
return;
end)
Option 3
game:BindToClose(function()
for _,Player in pairs(game.Players:GetPlayers()) do
DataService:saveData(Player):Fire()
end
end)