I am pretty sure the error is on line 4 so I will attempt to make another script that could probably help you understand how to use datastores and SetAsyncs, script in workspace, regular script!
game.Players.PlayerAdded:connect(function(p)
local count = 1
local plrKey = "Id-"..p.UserId
locla ds = game:GetService("DataStoreService"):GetDataStore("Data")
data = {} or nil
local savedValues = DataStore:GetAsync(key)
for _, SaveData in pairs(data) do
local NewValue = Instance.new("StringValue", workspace)
NewValue.Value = SaveData.Name
if savedValues then
NewValue.Value = savedValues[count]
count = count + 1
else
local valuesToSave = {NewValue.Value}
end
end
end
game.Players.PlayerRemoving:connect(function(p)
local key = "Id-"..p.userId
local valuesToSave = {data}
DataStore:SetAsync(key, valuesToSave)
end)
This is a rough untested example of how I would do things to save strings and use SetAsync ^, Hope this helps
1 comment
Found the solution getting the children took too long so when it was done the player was already gone and it couldnt take the userid from it to save.