Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Why DataStore Problem?

Anyone know the problem. People keep answering with an invalid format.

Game.Players.PlayerRemoving:connect(function(Player1)
local key = "user_" .. Player1.userId
Game:GetService("DataStoreService"):GetDataStore("Stats"):UpdateAsync(key, function(oldValue)
local Data1 = Player1:WaitForChild("leaderstats"):GetChildren()
for i= 1,#Data1 do
Data1:SetAsync(Data1[i].Name, Data1[i].Value) 
end
end)
end)

Game.Players.PlayerRemoving:connect(function(Player2)
local key = "user_"..Player2.userId
if Game:GetService("DataStoreService"):GetDataStore("Stats"):GetAsync(key) ~= nil then
local Data2 = Player2:WaitForChild("leaderstats"):GetChildren()
for i = 1, #Data2 do
Data2:GetAsync(Data2[i].Name)
end
end
end)

1 answer

Hey!


Game:GetService("DataStoreService"):GetDataStore("Stats"):UpdateAsync(key, function(oldValue)

I don't see any function related to oldValue! This may be your problem.

This discussion is preserved as it was. New answers, comments, and votes are closed.