function _G.SaveData(Player)
if Player:FindFirstChild(“StorageFile”) and Player:GetAttribute(‘Saved’) == nil then
Player:SetAttribute(‘Saved’,true)
local StorageFile = Player.StorageFile
local DataScope = 'TGData'.. _G.ScopeV1 ..Player.UserId ..'s'.. StorageFile.Customization.Team.Value
local DataStore = DataStoreService:GetDataStore("Data",DataScope)
local NewData = {}
for i,v in pairs(DataOrder) do
table.insert(NewData,StorageFile[DataOrderTypes[i]][v].Value)
end
print('saving')
DataStore:SetAsync(DataScope,NewData)
print('saved')
end
It’s not unnecessary, you have a warning telling you that there is an infinite yield on waiting for the StorageFolder. That is your issue not SetAsync, fix that, and you’ll fix the problem.
This is likely related to shutdown in Studio not the behaviour of SetAsync (and isn’t a bug).
Use :BindToClose:
game:BindToClose(function()
for _, player in Players:GetPlayers() do
Save(player)
end
end)
BindToClose’s callback will prevent the game from stopping for up to thirty seconds while the code in the callback completes. What is happening is you are hitting the stop button, which shuts down the internal server, and the thread spawned for the PlayerRemoving callback is killed once it begins yielding.
I don’t really understand the question… The problem though is that SetAsync is being interrupted by the server shutting down, so you need to use BindToClose to save player data as well.