Could anyone help me re-code for efficiency this? Because sometimes it does not load or save properly and i feel like I messed up on it (i think that why). If Anyone could help me?
Game.Players.PlayerAdded:connect(function(Player)
Player:WaitForChild("leaderstats")
wait(1/30)
local DataStore = Game:GetService("DataStoreService"):GetDataStore(Player.Name.."Stats")
for i,v in pairs(Player.leaderstats:GetChildren()) do
v.Value = DataStore:GetAsync(v.Name)
DataStore:UpdateAsync(v.Name, function(Current)
local Base = Current or 0
return Base
end)
end
end)
Game.Players.PlayerRemoving:connect(function(Player)
if Player:FindFirstChild("leaderstats") == nil then return end
local DataStore = Game:GetService("DataStoreService"):GetDataStore(Player.Name.."Stats")
for i,v in pairs(Player.leaderstats:GetChildren()) do
DataStore:SetAsync(v.Name, v.Value)
DataStore:UpdateAsync(v.Name, function(Current)
local Base = Current or 0
return Base
end)
end
end)

4 comments
Wow, you're a good scripter, I can't help though, I think this is too advanced. :/
I can just say that on line 20 the "or 0 " won't do a thing
Is their anyone with an answer? Really needing this right now.
I love datastore so I can try. :P