Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Is there any way to save lots of data?

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

✓ Accepted answer

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

3 comments

0

Thanks, that solved the issue I was having :D

0

This is not the proper way to solve this problem.

0

There are other methods that are more supported and better to handle.

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

5 comments

0

If I have any more issues I'll try your method but the one before seems to be working now.

0

Okay. This is the official one anyway.

0

And simpler, too.

0

Ok, well I'm probably gonna go off now so I'll try it out tomorrow, thanks.

0

yeah this is the correct way to do it lol, my one is a poor man's version

This discussion is preserved as it was. New answers, comments, and votes are closed.