Okay so im trying to save this stringvalue in a folder in players location but i keep getting this error:
11:15:18.591 Argument 2 missing or nil - Server - MainData:49
idk why im getting this but i do need help
heres script:
local service = game:GetService("DataStoreService") local datastore = service:GetDataStore("Stats") local function save(player) local success,errormessage = pcall(function() local SaveData = {} for i,stats in pairs(player["Data Folder"]:GetChildren()) do SaveData[stats.Name] = stats.Value end datastore:SetAsync(player.UserId,SaveData) end) if not success then return datastore end end game.Players.PlayerAdded:Connect(function(player) print'Joined' local datafolder = Instance.new("Folder",player) datafolder.Name = "Data Folder" local hakifolder = Instance.new("Folder",workspace:WaitForChild(player.Name)) hakifolder.Name = "Buso" local fruitvalue = Instance.new("StringValue",datafolder) fruitvalue.Name = "Fruit" wait(.1) if not player:WaitForChild'Data Folder' then return end if player:WaitForChild'Data Folder'.Fruit.Value == "" then player["Data Folder"].Fruit.Value = "None" -- changes the value of it end print'loaded data folder' local data local success, errormessage = pcall(function() data = datastore:SetAsync(player.UserId) end) if success then for i,stats in pairs(datafolder:GetChildren()) do stats.Value = data[stats.Name] end print("Success") else print("failed") warn(errormessage) end end) game.Players.PlayerRemoving:Connect(function(player) save() end)
help B)
On line 38, you call SetAsync()
I am guessing to retrieve data. You need to change that to GetAsync
Therefore to fix this, simply do:
local service = game:GetService("DataStoreService") local datastore = service:GetDataStore("Stats") local function save(player) local success,errormessage = pcall(function() local SaveData = {} for i,stats in pairs(player["Data Folder"]:GetChildren()) do SaveData[stats.Name] = stats.Value end datastore:SetAsync(player.UserId,SaveData) end) if not success then return datastore end end game.Players.PlayerAdded:Connect(function(player) print'Joined' local datafolder = Instance.new("Folder",player) datafolder.Name = "Data Folder" local hakifolder = Instance.new("Folder",workspace:WaitForChild(player.Name)) hakifolder.Name = "Buso" local fruitvalue = Instance.new("StringValue",datafolder) fruitvalue.Name = "Fruit" wait(.1) if not player:WaitForChild'Data Folder' then return end if player:WaitForChild'Data Folder'.Fruit.Value == "" then player["Data Folder"].Fruit.Value = "None" -- changes the value of it end print'loaded data folder' local data local success, errormessage = pcall(function() data = datastore:GetAsync(player.UserId) end) if success then for i,stats in pairs(datafolder:GetChildren()) do stats.Value = data[stats.Name] end print("Success") else print("failed") warn(errormessage) end end) game.Players.PlayerRemoving:Connect(function(player) save() end)