It basically just stops the game server from closing until that function you put into it has been completed you can look at the documentation here: DataModel | Documentation - Roblox Creator Hub
local function SaveData(player)
local success, errormessage = pcall(function()
DS:SetAsync("deaths-"..player.UserId, player.leaderstats.Deaths.Value)
DS:SetAsync("wins-"..player.UserId, player.leaderstats.Wins.Value)
DS:SetAsync("koi-"..player.UserId, player.leaderstats.Koi.Value)
end)
end
local function GameBind()
for i,v in pairs(game.Players:GetPlayers) do
SaveData(v)
end
end
game:BindToClose(GameBind)
It sent me this DataStore request was added to queue. If request queue fills, further requests will be dropped. Try sending fewer requests.Key = wins-526801380
local dataStoreService = game:GetService("DataStoreService")
local DS = dataStoreService:GetDataStore("LeaderSave")
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
--------
local koi = Instance.new("IntValue")
koi.Name = "Koi"
koi.Value = 0 -- Always 100
koi.Parent = leaderstats
local wins = Instance.new("IntValue")
wins.Name = "Wins"
wins.Value = 0
wins.Parent = leaderstats
local deaths = Instance.new("IntValue")
deaths.Name = "Deaths"
deaths.Value = 0
deaths.Parent = leaderstats
-------
local comets = Instance.new("IntValue")
comets.Name = "Comets"
comets.Value = 0
comets.Parent = leaderstats
--[[
Coments. 20 Comets : 1 Koi. If Comets are not exactly a 20 multiple, then it will be rounded to the nearest
twenty. If it's not convertable, then it will be rounded down.]]
print("Leaderstats Loaded!")
--------------------------------------------
local function SaveData(player)
local success, errormessage = pcall(function()
DS:SetAsync("deaths-"..player.UserId, player.leaderstats.Deaths.Value)
DS:SetAsync("wins-"..player.UserId, player.leaderstats.Wins.Value)
DS:SetAsync("koi-"..player.UserId, player.leaderstats.Koi.Value)
end)
end
local function GameBind()
for i,v in pairs(game.Players:GetPlayers()) do
SaveData(v)
end
end
game:BindToClose(GameBind)
end)
game.Players.PlayerRemoving:Connect(function(player)
local success, errormessage = pcall(function()
DS:SetAsync("deaths-"..player.UserId, player.leaderstats.Deaths.Value)
DS:SetAsync("wins-"..player.UserId, player.leaderstats.Wins.Value)
DS:SetAsync("koi-"..player.UserId, player.leaderstats.Koi.Value)
end)
end)
Not necessarily on topic, but is there a reason you save data like this? You do know you can save tables, right? You would only need to use GetAsync once for all of these.
local data = {
Deaths = player.leaderstats.Deaths.Value;
Wins = player.leaderstats.Wins.Value;
Koi = player.leaderstats.Koi.Value;
}
DS:SetAsync(player.UserId, data)