Good day everyone who, is reading this(it is currently midnight here where I’m making this post, so it might not come out perfectly as I want it to, if you are having trouble with what I’m trying to get at, just let me know.
But anyway, I want to make this plot system, kind of like the one in the game “My farm” and “Bee Swarm Sim.”( I know there are other forums out there, I do not understand most of them), where it saves the objects inside of the plot the player is in then make the plot they were in have a “default plot” when they leave. I have been trying to do this for a while now, and still no result.
There is now issue really, except the fact that I have no Idea on how to do this. I thought that saving a table through dataStore2 would work, but could not find anything too helpful, and I never used serialization(I have absolutely no Idea what this is) before.
I have been looking all over the internet, and I saw Alvin_Blox’s video on making a plot select system, and that was probably the closest thing that I can find to that, through searching on Google, on the devforum, as I said before, I just could not understand it.
I recommend using normal DataStores due to the fact that there’s a less chance of that just breaking and using normal datastores to store tables is easy.
local DataStoreService = game:GetService("DataStoreService")
local plotsStore = DataStoreService:GetDataStore("plotsStore")
game.Players.PlayerAdded:Connect(function(plr)
local success, data = pcall(function()
return plotsStore:GetAsync("plr")
end)
if success then
...
else
...
end
end)
game.Players.PlayerRemoving:Connect(function(plr)
saveData = {
...
}
local success, data = pcall(function()
return plotsStore:SetAsync("plr", saveData)
end)
if success then
...
end
end)
I’m assuming a plot system is the ability to place objects down? If you have no idea how to script that particular thing, or have no knowledge about a certain subject, you can look at the API, looking at examples or free models that are kind of what you want and learning from them as well will get you closer to your goal.
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.
When saving data for plot, theres a few things to keep in mind for each structure:
Position: Where it is in relative to the center of the plot. Try to keep it at a max of two decimals if possible, because there is a data cap although its high. I like to save my positions down to the hundredth.
Orientation: How is it oriented? I usually snap each axis to a 1 degree increment.
Type: What kind of structure is it? Is it a wall, a door, a carpet, a table, what kind?
(if the user is allowed to customize these)
Material: What material is it made out of?
Color: What color is it made out of?
If you save each blueprint as a table according to these points, you should be set. You can just loop through the table of these objects when your loading the data in on join.
It’s important to keep in mind the datastore limit. Yes, it is high, but if you not careful, there’s a chance a user will hit it. Don’t let every number run down 8 decimal places. Each character is one more towards the datastore cap, so I think it’s important to pay some attention to. I usually round orientations to 1 degree, and positions down to .01. You could also make other tables for colors and materials based on your game if you really wanted to.