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

What is the best way to save patterns of data?

So I originally asked this question here, but it turns out when you attempt to store a dictionary you get the following error:

22:22:06.902 - Cannot store Dictionary in DataStore
22:22:06.902 - Stack Begin
22:22:06.903 - Script 'ServerScriptService.SHScript', Line 66
22:22:06.903 - Stack End

Which suggests dictionaries aren't an option (no matter how useful they would be)!

This means my question still stands, how can I save quite a big amount of data for a randomized pattern. Imagine you join a game and the game creates a pattern of 12,500 bricks of random colours, such as the one here, when you leave and come back the SAME image should be loaded into the game.

Dictionaries would have worked, if I was able to save them with data stores. But I can't. Can you think of any (realistic) examples? Typing out thousands of lines into a table isn't a realistic option unfortunately. Could anyone suggest an alternative?

Thanks!

Note: The type of game I'm going for is similar to retail tycoon/theme park tycoon.

2 comments

0

Dictionaries do work according to the wiki...

0

@LordDragonZord, you get a error if you try to save a dictionary

2 answers

You can save dictionaries to data store. The only limit on saving a table to data store, is it's encoded JSON string size which the wiki mentions here. After a simple test and comparing error messages, it's pretty clear you're trying to save something in your dictionary that doesn't belong there. JSON is pretty straight forward, and is only going to be compatible with primitive data types such as:

  • Strings
  • Booleans
  • Numbers
  • Nil
  • Tables
    • Automatically encoded/decoded upon saving/getting them.

Anything else is specific to ROBLOX or strictly Lua, and therefore must be serialized. This is why you should be saving information about objects, not the objects themselves.

1 comment

0

Thanks so much! I was trying to save BrickColor, I suppose that's why I was getting an error. :)

#What you could do? Use loadstring. It makes your game vulnerable to exploits but FE should prevent most. Make sure you set LoadStringEnabled to true in ServerScriptService.


#Save all your data into a string

local properties = {"Name", "BrickColor"} --properties you need to save
local uis = game:GetService("DataStoreService"):GetDataStore("SaveBlocks")
local block = workspace.Part --Block

function datatostring(obj)
	local listofstring = {}
	for _,v in pairs(properties) do
		table.insert(listofstring,obj..v.." = "..obj[v])
	end
end

uis:SetAsync(player.UserId, datatostring(block))

#How do you retrieve the data? Get the table and load the codes inside.

local uis = game:GetService("DataStoreService"):GetDataStore("SaveBlocks")
local codes = uis:GetAsync(Player.UserId)
local block = workspace.Part --Make sure it's the same part

local loaddata(obj)
	for _,v in pairs(codes) do
		loadstring(codes)()
	end
end


Hope it helps!(Like always edit the code!)

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