So I'm trying to make a way for someone to paint a map, then save what they've painted. I've tried to save the position of each part and its color, but I get a "cannot store array in datastore" error, and from what I've looked up I'm guessing that's because I'm trying to save too much data, so does anyone know a different way I could achieve this, or if there's something else I'm doing wrong??
What I tried:
mapSaves=DataStore:GetDataStore("mapSaves") game.Players.PlayerAdded:connect(function(player) player.Chatted:connect(function(chat) if chat == "smap" then local saveTable={Potato=4} for i,v in pairs (workspace.worldMap:GetDescendants()) do if v:IsA("Part") or v:IsA("UnionOperation") then table.insert(saveTable,v.BrickColor) end end for i,v in pairs (saveTable) do print(i.."="..tostring(v)) end mapSaves:SetAsync(player.UserId,saveTable) end end) end)
I've had the same problem recently, but I've found a way to get over it. It might be long but trust me it works.
mapSaves=DataStore:GetDataStore("mapSaves") game.Players.PlayerAdded:connect(function(player) player.Chatted:connect(function(chat) if chat == "smap" then local saveTable={Potato=4} for i,v in pairs (workspace.worldMap:GetDescendants()) do if v:IsA("Part") or v:IsA("UnionOperation") then table.insert(saveTable,v.Color.r) table.insert(saveTable,v.Color.g) table.insert(saveTable,v.Color.b) end end for i,v in pairs (saveTable) do print(i.."="..tostring(v)) end mapSaves:SetAsync(player.UserId,saveTable) end end) end)
What I have done is saved the RGB values of the part color seperately so that it saves into the array ~tantec
Use JSONEncode and JSONDecode function of the HttpService to store data as JSON, a format that can be used in Datastores.
When you want to submit something to a datastore, do
game:GetService("HttpService"):JSONEncode(data) -- Returns string in JSON format
this will return a string (That is in JSON format), which can be uploaded to a datastore.
When you get the datastore, use the JSONDecode function to make the string the thing it was before (an array, in this case)
game:GetService("HttpService"):JSONDecode(string) -- Returns your data as it was before
Hope this helped!