GlobalDataStore:SetAsync() requires 3 arguments, while you only supplied 2. GlobalDataStore:SetAsync(key : string, value : any, userids : Array)
You can also supply 4 arguments:
GlobalDataStore:SetAsync(key: string, value: Variant, userIds: Array, options: DataStoreSetOptions)
local Players = game:GetService("Players")
local DSS = game:GetService("DataStoreService")
local leaderstatsData = DSS:GetDataStore("leaderstatsDataStuff")
local function SaveData(player, data)
local success, errorMessage = pcall(function()
leaderstatsData:SetAsync(player.UserId, data)
end)
if not success then
warn(errorMessage)
end
end
Players.PlayerAdded:Connect(function(player)
local playerData = leaderstatsData:GetAsync(player.UserId)
if playerData then
player.leaderstats.Dances.Value = playerData.Dances
player.leaderstats.Rebirths.Value = playerData.Rebirths
end
end)
Players.PlayerRemoving:Connect(function(player)
local playerData = {
Dances = player.leaderstats.Dances.Value,
Rebirths = player.leaderstats.Rebirths.Value
}
SaveData(player, playerData)
end)
game:BindToClose(function()
for i, player in Players:GetPlayers() do
local playerData = {
Dances = player.leaderstats.Dances.Value,
Rebirths = player.leaderstats.Rebirths.Value
}
SaveData(player, playerData)
end
end)
Hello, if the issue revolves around loading the save, try inspecting what the DataStore table looks like. You can use this code to view the table upon loading in the game:
local DSS = game:GetService("DataStoreService")
local leaderstatsData = DSS:GetDataStore("leaderstatsDataStuff")
game.Players.PlayerAdded:Connect(function(player)
local playerData = leaderstatsData:GetAsync(tostring(player.UserId))
print(playerData)
if playerData then
player.leaderstats.Dances.Value = playerData["Dances"]
player.leaderstats.Rebirths.Value = playerData["Rebirths"]
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local playerData = {
["Dances"] = player.leaderstats.Dances.Value;
["Rebirths"] = player.leaderstats.Rebirths.Value;
}
leaderstatsData:SetAsync(tostring(player.UserId), playerData)
end)
And please show me what result you got.
I also made some changes, it might help.