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

Data Store Problem? [Un-Solved]

Asked by 10 years ago

Someone helped me with a DataStore that should automatically save and load and it appears to do nothing with no error.

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)
0
Dude that's my answer from before, I can understand that you copy and pasted, q.q! HexC3D 830 — 10y
0
Ummm, i said someone helped me. (You). But it did not really work at all. peoplemove12 148 — 10y
0
Well I notice a few mistakes so I can fix it , mk HexC3D 830 — 10y

1 answer

Log in to vote
-1
Answered by
HexC3D 830 Moderation Voter
10 years ago
local datastore = game:GetService("DataStoreService"):GetDataStore("Stats")

game.Players.PlayerRemoving:connect(function(player)
player:WaitForDataReady() 
wait(4)
local p1 = player:FindFirstChild("leaderstats"):GetChildren()
for i = 1, #p1 do 
datastore:SetAsync(p1[i].Name, p1[i].Value)
end
end)

Simply this will save a players data.

game.Players.PlayerAdded:connect(function(nplayer)
nplayer:WaitForDataReady() 
wait(4) -- I added this on
local p2 = newplayer:FindFirstChild("leaderstats"):GetChildren()
for i = 1, #p2 do
p2[i].Value = datastore:GetAsync(p2[i].Name)
end
end)

Hmm Try this, I mean this should work I made this one out of my game.

+1 if this worked and helped!!

0
player:WaitForDataReady() is not needed. DataStore is always ready to be loaded. peoplemove12 148 — 10y
0
Well try it. HexC3D 830 — 10y
0
I noticed you fire the function "nplayer" but in line 4 on the second player its newplayer witch is invalid. peoplemove12 148 — 10y
0
Fixed it HexC3D 830 — 10y
View all comments (2 more)
0
This does not work. peoplemove12 148 — 10y
0
Wierd. HexC3D 830 — 10y
Ad

Answer this question