I've made multiple data stores before and this has never occurred. I'm making a new one rn and it gives me an error say "ServerScriptService.Saving:31: bad argument #3(string expected, got nil)". Is this even fixable?
game.Players.PlayerRemoving:Connect(function(player)
local statstorage = game.ReplicatedStorage.PlayerData:FindFirstChild(player.UserId):GetChildren()
for i = 1, #statstorage do
local datastore = game:GetService("DataStoreService"):GetOrderedDataStore(statstorage[i].Name)
datastore:SetAsync(player.UserId, statstorage[i].Value)
end
end)
function Save(player)
local statstorage = game.ReplicatedStorage.PlayerData:FindFirstChild(player.UserId):GetChildren()
for i = 1, #statstorage do
local datastore = game:GetService("DataStoreService"):GetOrderedDataStore(statstorage[i].Name)
datastore:SetAsync(player.UserId, statstorage[i].Value)
end
end
------------------------------------------------------------------------------
game.Players.PlayerAdded:Connect(function(player)
spawn(function()
while true do
wait(600)
Save(player)
end
end)
game.ReplicatedStorage.PlayerData:WaitForChild(player.UserId)
wait(1)
local stats = game.ReplicatedStorage.PlayerData:WaitForChild(player.UserId):GetChildren()
for i = 1, #stats do
local datastore = game:GetService("DataStoreService"):GetOrderedDataStore(stats[i].Name)
stats[i].Value = datastore:GetAsync(player.UserId)
end
end)

1 comment
The error "ServerScriptService.Saving:31: bad argument #3(string expected, got nil)" means that it is expecting a string value but the value that is being passed in is nil. Judging by how the error is talking about this line "stats[i].Value = datastore:GetAsync(player.UserId)" (line 31), it looks like you are setting stats[i].Value before the GetAsync can return anything.