Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Is there any way to save lots of data?

Asked by 5 years ago

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)

2 answers

Log in to vote
0
Answered by
tantec 305 Moderation Voter
5 years ago

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

0
Thanks, that solved the issue I was having :D BetterNotDie 11 — 5y
0
This is not the proper way to solve this problem. Aimarekin 345 — 5y
0
There are other methods that are more supported and better to handle. Aimarekin 345 — 5y
Ad
Log in to vote
0
Answered by
Aimarekin 345 Moderation Voter
5 years ago

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!

Link to the Http Service

0
If I have any more issues I'll try your method but the one before seems to be working now. BetterNotDie 11 — 5y
0
Okay. This is the official one anyway. Aimarekin 345 — 5y
0
And simpler, too. Aimarekin 345 — 5y
0
Ok, well I'm probably gonna go off now so I'll try it out tomorrow, thanks. BetterNotDie 11 — 5y
0
yeah this is the correct way to do it lol, my one is a poor man's version tantec 305 — 5y

Answer this question