Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why DataStore Problem?

Asked by 10 years ago

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

Log in to vote
0
Answered by 10 years ago

Hey!


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

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

Ad

Answer this question