Hello ![]()
I do only one SetAsync when player leave the game but if got this warning :
DataStore request was added to queue. If request queue fills, further requests will be dropped. Try sending fewer requests.Key = 133539203
Here my code ![]()
local dataStore = game:GetService("DataStoreService")
local players = game:GetService("Players")
local serverStorage = game:GetService("ServerStorage")
local starterGui = game:GetService("StarterGui")
local modules = serverStorage:WaitForChild("Modules")
local createStats = require(modules:WaitForChild("Stats"))
local saveCooldown = 5*60 -- 5 minutes
local playerStore = dataStore:GetDataStore(createStats["DataStoreName"]["Player"])
players.PlayerAdded:Connect(function(player)
createStats.loadData(playerStore,player.UserId)
end)
local function saveData(player,playerLeave)
local playerLeaderstats = player:WaitForChild("leaderstats")
local leaderstats = createStats.getDataTable(playerLeaderstats)
local data = {
["leaderstats"] = leaderstats,
}
local userId = player.UserId
local setSuccess,errorMessage = pcall(function()
return playerStore:SetAsync(userId,data)
end)
end
players.PlayerRemoving:Connect(function(player)
saveData(player,true)
print("playerremoving")
end)
game:BindToClose(function()
for _,player in pairs(players:GetPlayers()) do
print("playerClosed")
saveData(player,true)
end
end)
while wait(saveCooldown) do
for _,player in pairs(players:GetPlayers()) do
saveData(player)
end
end
Thank you ![]()