Skip to content
This repository has been archived by the owner on Jul 28, 2022. It is now read-only.

Commit

Permalink
Update Data.lua
Browse files Browse the repository at this point in the history
  • Loading branch information
Acecateer authored May 18, 2019
1 parent 20d4d91 commit a1c7f93
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/ServerStorage/Aero/Modules/Data.lua
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,30 @@ function Data:Start()
end
end
end

local function FireBoundToCloseCallbacks()
local numBinded = #self._onCloseHandlers
if (numBinded == 0) then return end
local Bindable = Instance.new("BindableEvent")
local numCompleted = 0

for _,func in pairs(self.onCloseHandlers) do
spawn(function()
local success, err = pcall(func)
if (not success) then
warn("BindToClose function errored: " .. tostring(err))
end

numCompleted = (numCompleted + 1)
if (numCompleted == numBinded) then
Bindable:Fire()
end
end)
end

Bindable.Event:Wait()
Bindable:Destroy()
end

local function AutoSaveAllData()
if (autoSaving) then return end
Expand Down Expand Up @@ -523,6 +547,7 @@ function Data:Start()
-- Auto-save all data before server closes:
game:BindToClose(function()
gameClosing = true
FireBoundToCloseCallbacks()
AutoSaveAllData()
end)
end
Expand Down

0 comments on commit a1c7f93

Please sign in to comment.