If you’re trying to create a system where you can place objects, this is a very helpful tutorial:
Some other things you mentioned having trouble with are saving, and serialization.
I will quickly explain Serializtion, and how it then related to saving data.
Serialization is the process of converting an object into a stream of bytes to store the object or transmit it to memory, a database, or a file.
For your purpose, you wouldn’t be converting it into bytes, but rather just a format that you could later decode.
An example of this is if you had a word like “Hello” and you wanted to give that a numerical value because you can only save numbers. You could use something like Unicode, or you could create your own method. My example method would be giving each letter in the alphabet a number from 1-26 like this:
a = 01
b = 02
c = 03
etc...
with this format “Hello” would translate to “0805121215”. You could then pass that to your function, or store it to your file. When you needed it again, you could decode it using the reverse of the method you use to encode it, so the result would be “hello”. Notice though, how the result is “hello” and not “Hello”, because I only had one set of values for the alphabet which meant I could only have either all lowercase or all uppercase. You can very simply just add more numbers or “code” or whatever you’re using to give yourself more options.
A very common/very basic way of Serialization in roblox is just to put all of the information into a table. Roblox then automatically converts that table into JSON code, which is stored in the Datastore. If you are needing everything to be a string for example, you could take all of your information and put it into a string separated by commas, like “Hi” “123” “boo” and “true” would all be the values, you could then put them all into the same string like: “Hi,123,boo,true”. Then you’re decoder can split them part with string.split()
, and then assign each value to it’s appropriate data type.
How does Serialization connect to saving data? You need to get everything into one object so that it can be saved. If you have an object with all of it’s properties, for example BrickColor, Size, CFrame, etc. You can take all of those values and create a dictionary that holds all of it.
local P = workspace.Part --part to serialize and save.
local myObject = {
BrickColor = Part.BrickColor,
Size = Part.Size,
CFrame = Part.CFrame,
...--Any other values
}
Then you can save that table as you would anything else. Keep in mind though that you CANNOT mix indices. You cannot have an Array (numerical indices) mixed with a Dictionary (string indices), you must have one or the other.
local Datastore = game:GetService("DataStoreService"):GetDataStore("Data")
local key = --something here to define where to store the information so it can be retrieved again. (Should be original for all objects, if you use the same key for two things, the most recent one will overwrite the older one)
local success, err = pcall(function()
Datastore:SetAsync(key, myObject)
end)
I hope this helps you, if you need me to break down any parts, just reply to this message.