Hey guys,
Let me place my big chunky script first.
local DataStoreService = game:GetService("DataStoreService") local DataStore = DataStoreService:GetDataStore("TrialShopDataStore") game.Players.PlayerAdded:Connect(function(player) wait() local data local OwnedTrailsFolder = game.ReplicatedStorage[player.Name..'OwnedTrails'] local Trail1 = OwnedTrailsFolder['#1 Black Trail'] local Trail2 = OwnedTrailsFolder['#2 Blue Trail'] local Trail3 = OwnedTrailsFolder['#3 Green Trail'] local Trail4 = OwnedTrailsFolder['#4 Purple Trail'] local Trail5 = OwnedTrailsFolder['#5 Red Trail'] local Trail6 = OwnedTrailsFolder['#6 Pink Trail'] local Trail7 = OwnedTrailsFolder['#7 Nyan Cat Trail'] local Trail8 = OwnedTrailsFolder['#8 Flag of the Netherlands'] local EquippedTrail = game.ReplicatedStorage[player.Name..'OwnedTrails'].EquippedTrail local Table1 = DataStore:GetAsync(player.UserId) local success, errormessage = pcall(function() warn('#1') --data = myDataStore:GetAsync(player.UserId.."-cash") local Table1 = DataStore:GetAsync(player.UserId) if Table1 then wait() Trail1.Value = Table1[1] Trail2.Value = Table1[2] Trail3.Value = Table1[3] Trail4.Value = Table1[4] Trail5.Value = Table1[5] Trail6.Value = Table1[6] Trail7.Value = Table1[7] Trail8.Value = Table1[8] local TableOneNine = tostring(Table1[9].Value) print('Table1[9] Before ToString: ',Table1[9].Value,'. After ToString: ',TableOneNine) -- Prints Twice 'nil' EquippedTrail.Value = Table1[9] else warn('#3') end warn('#4') end) if success then else warn("There was an error whilst getting your data") warn(errormessage) -- This error message = 36: Invalid Argument #3 (String expected, got table) end end) game.Players.PlayerRemoving:Connect(function(player) local OwnedTrailsFolder = game.ReplicatedStorage[player.Name..'OwnedTrails'] local Trail1 = OwnedTrailsFolder['#1 Black Trail'] local Trail2 = OwnedTrailsFolder['#2 Blue Trail'] local Trail3 = OwnedTrailsFolder['#3 Green Trail'] local Trail4 = OwnedTrailsFolder['#4 Purple Trail'] local Trail5 = OwnedTrailsFolder['#5 Red Trail'] local Trail6 = OwnedTrailsFolder['#6 Pink Trail'] local Trail7 = OwnedTrailsFolder['#7 Nyan Cat Trail'] local Trail8 = OwnedTrailsFolder['#8 Flag of the Netherlands'] local EqTrail local EquippedTrail = game.ReplicatedStorage[player.Name..'OwnedTrails'].EquippedTrail local Save = {} local success, errormessage = pcall(function() table.insert(Save, #Save+1, {player.UserId .. "Trail1", Trail1.Value}) table.insert(Save, #Save+1, {player.UserId .. "Trail2", Trail2.Value}) table.insert(Save, #Save+1, {player.UserId .. "Trail3", Trail3.Value}) table.insert(Save, #Save+1, {player.UserId .. "Trail4", Trail4.Value}) table.insert(Save, #Save+1, {player.UserId .. "Trail5", Trail5.Value}) table.insert(Save, #Save+1, {player.UserId .. "Trail6", Trail6.Value}) table.insert(Save, #Save+1, {player.UserId .. "Trail7", Trail7.Value}) table.insert(Save, #Save+1, {player.UserId .. "Trail8", Trail8.Value}) EquippedTrail = tostring(EquippedTrail.Value) print('EquippedTrail = ',EquippedTrail) wait() table.insert(Save, #Save+1, {player.UserId .. "EquippedTrail", EquippedTrail}) wait() DataStore:SetAsync(player.UserId, Save) end) if success then else warn('IMPORTANT: ',errormessage) -- No error-message when saving! end end)
THE ERROR MESSAGE: "36: Invalid Argument #3 (String expected, got table)"
I'm new to DataStoreService & new to Table's, Rip me. I've tried to use 'ToString' and stuff, but i seem not be able to fix it. I'm not sure what the errors means, nor how to fix it.
I'm sorry for my grammar. I'm Dutch. So English ain't my native language.
DataStores simply cannot store raw table data, only strings. So you must transform the table into a string. Your best option is to use HTTPService:JSONEncode().
Ex.
local tab = {"a", "b", "c"} local json = HTTPService:JSONEncode(tab) DataStore:SetAsync(player.UserId, json)
When you want to retrieve the table you can do so with HTTPService:JSONDecode().
Ex.
local json = DataStore:GetAsync(player.UserId) local tab = HTTPService:JSONDecode(json)
BTW, your English is perfect. Other then apostrophes being used for plural words when they are supposed to be used with possessive words.
Should work :
local DataStoreService = game:GetService("DataStoreService") local DataStore = DataStoreService:GetDataStore("TrialShopDataStore") game.Players.PlayerAdded:Connect(function(player) wait() local data local OwnedTrailsFolder = game.ReplicatedStorage[player.Name..'OwnedTrails'] local Trail1 = OwnedTrailsFolder['#1 Black Trail'] local Trail2 = OwnedTrailsFolder['#2 Blue Trail'] local Trail3 = OwnedTrailsFolder['#3 Green Trail'] local Trail4 = OwnedTrailsFolder['#4 Purple Trail'] local Trail5 = OwnedTrailsFolder['#5 Red Trail'] local Trail6 = OwnedTrailsFolder['#6 Pink Trail'] local Trail7 = OwnedTrailsFolder['#7 Nyan Cat Trail'] local Trail8 = OwnedTrailsFolder['#8 Flag of the Netherlands'] local EquippedTrail = game.ReplicatedStorage[player.Name..'OwnedTrails'].EquippedTrail local Table1 = DataStore:GetAsync(player.UserId) local success, errormessage = pcall(function() warn('#1') --data = myDataStore:GetAsync(player.UserId.."-cash") local Table1 = DataStore:GetAsync(player.UserId) if Table1 then wait() Trail1.Value = Table1[1] Trail2.Value = Table1[2] Trail3.Value = Table1[3] Trail4.Value = Table1[4] Trail5.Value = Table1[5] Trail6.Value = Table1[6] Trail7.Value = Table1[7] Trail8.Value = Table1[8] local TableOneNine = tostring(Table1[9].Value) print('Table1[9] Before ToString: ',Table1[9].Value,'. After ToString: ',TableOneNine) -- Prints Twice 'nil' EquippedTrail.Value = Table1[9] else warn('#3') end warn('#4') end) if success then else warn("There was an error whilst getting your data") warn(errormessage) -- This error message = 36: Invalid Argument #3 (String expected, got table) end end) game.Players.PlayerRemoving:Connect(function(player) local OwnedTrailsFolder = game.ReplicatedStorage[player.Name..'OwnedTrails'] local Trail1 = OwnedTrailsFolder['#1 Black Trail'] local Trail2 = OwnedTrailsFolder['#2 Blue Trail'] local Trail3 = OwnedTrailsFolder['#3 Green Trail'] local Trail4 = OwnedTrailsFolder['#4 Purple Trail'] local Trail5 = OwnedTrailsFolder['#5 Red Trail'] local Trail6 = OwnedTrailsFolder['#6 Pink Trail'] local Trail7 = OwnedTrailsFolder['#7 Nyan Cat Trail'] local Trail8 = OwnedTrailsFolder['#8 Flag of the Netherlands'] local EqTrail local EquippedTrail = game.ReplicatedStorage[player.Name..'OwnedTrails'].EquippedTrail local Save = {} local success, errormessage = pcall(function() table.insert(Save, #Save+1, {player.UserId .. "Trail1", Trail1.Value}) table.insert(Save, #Save+1, {player.UserId .. "Trail2", Trail2.Value}) table.insert(Save, #Save+1, {player.UserId .. "Trail3", Trail3.Value}) table.insert(Save, #Save+1, {player.UserId .. "Trail4", Trail4.Value}) table.insert(Save, #Save+1, {player.UserId .. "Trail5", Trail5.Value}) table.insert(Save, #Save+1, {player.UserId .. "Trail6", Trail6.Value}) table.insert(Save, #Save+1, {player.UserId .. "Trail7", Trail7.Value}) table.insert(Save, #Save+1, {player.UserId .. "Trail8", Trail8.Value}) EquippedTrail = tostring(EquippedTrail.Value) print('EquippedTrail = ',EquippedTrail) wait() table.insert(Save, #Save+1, {player.UserId .. "EquippedTrail", EquippedTrail}) wait() DataStore:SetAsync(player.UserId, Save) end) if success then else warn('IMPORTANT: ',errormessage) -- No error-message when saving! end end)