I’ve been having this issue for a while, and basically I have a script that is supposed to save data using update async, but for some reason its not. There are no errors in the output. Nothing.
Load data function:
local function loadPlayerData(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local currency1 = Instance.new("IntValue")
currency1.Name = "Coins"
currency1.Parent = leaderstats
local currency2 = Instance.new("IntValue")
currency2.Name = "Gems"
currency2.Parent = leaderstats
local data = nil
local success, err = pcall(function()
data = dataStore:GetAsync(player.UserId)
end)
if success then
print("Successfully loaded player data for "..player.Name)
if data then
loadedPlayerData[player] = data
currency1.Value = data.Coins
currency2.Value = data.Gems
else
loadedPlayerData[player] = {DataId = 0, Coins = defaultCoins, Gems = 0}
currency1.Value = defaultCoins
currency2.Value = 0
end
else
warn("Data Store: "..err)
end
end
Save data function:
local playersData = loadedPlayerData[player]
if playersData then
local success, err = pcall(function()
dataStore:UpdateAsync(player.UserId, function(oldValue)
print(1)
local previousData = oldValue or {DataId = 0}
print(2)
if playersData.DataId == previousData.DataId then
print(3)
playersData.DataId = playersData.DataId + 1
print(4)
return playersData
else
print(5)
warn("Couldn't save data for "..player.Name)
print(6)
return nil -- rip
end
end)
end)
if success then
print("Successfully saved player data for "..player.Name)
else
warn("Data Store: "..err)
end
loadedPlayerData[player] = nil
end
end
The save data function is inside a player removing function. It is supposed to print 1, 2, 3, 4. But it doesn’t print anything at all. Can someone please tell me why this isn’t doing anything?