I made a datastore that's saving "leader stats" values. But it's not saving/loading it?
code:
game.Players.PlayerRemoving:Connect(function(player)
local datastore = game:GetService("DataStoreService"):GetDataStore("SaveStats")
local statstorage = player:WaitForChild("Currency"):GetChildren()
for i = 1, #statstorage do
pcall(function()
datastore:SetAsync(statstorage[i].Name, statstorage[i].Value)
print("saving..")
end)
end
end)
game.Players.PlayerAdded:Connect(function(player)
local datastore = game:GetService("DataStoreService"):GetDataStore("SaveStats")
player:WaitForChild("Currency")
wait(1)
local stats = player:FindFirstChild("Currency"):GetChildren()
for i = 1, #stats do
pcall(function()
stats[i].Value = datastore:GetAsync(stats[i].Name)
end)
print("loading")
end
end)

6 comments
It prints loading two times though..
PlayerAdded is before PlayerRemoving. Thats probably why.
It's a event. Does not need to be in any specific order.
Then, try joining yourself first and then bringing in another player, see if that other players data is loaded.
I think it is a event.
It dosen't matter if you have one or more players. It should load for everyone.