I am trying to make a sandbox tycoon and I have the plot system done but I cant figure out how to save any object that is above or touching the plot
Here’s where stuff is located
I am trying to make a sandbox tycoon and I have the plot system done but I cant figure out how to save any object that is above or touching the plot
Here’s where stuff is located
You could give them a tag of the players name or if you store the plots objects in a folder, then you can do a for loop, though the folder or the collenctionserivce, when they leave and save then delete them.
Here are the basic steps:
You need cloneables, preferably in ReplicatedStorage
When a save needs to happen, serialize all of the data you need to re-create the items and save it in the DataStore
When a load needs to happen, deserialize all of the data, cloning the items back onto the plot (with their data populated)
Writing custom serialization code can be a hassle (as is interacting with DataStoreService), but it is what you need to do to store data like this if you don’t want to learn a custom library, like ProfileService
Hello Thanks For Replying How Do You Serialize Parts I Don’t Understand What Serialize In This Context Means
so it’s pretty complicated, actually it’s easy once you understand, I only understood plot saving after four years of development.
Let’s say you have a table of parts you want to save, now you need to convert that table into a table that uses no instances and only bool or string data
local instanceTable = {workspace.Part}
local serialTable = {}
for index, value in instanceTable do
serialTable[index] = {
Color = value.Color, -- and so on.
}
end
then you would have to use :GetAsync()
and :SetAsync()
or something like that. I recommend using a tutorial if you don’t know what it means still.
Yeah it’s actually pretty simple to understand. When you save data using the DataStoreService, it needs to be in the form of a Lua table with basic values, which are string
, number
, and boolean
For example, if you want to save the position (Vector3) of an item on the plot, you have to convert that position value to a table, such as:
local serializedPos = { pos.X, pos.Y, pos.Z }
-- save to data store
and when you load the data back in, you have to convert it back to the right format:
-- get from data store
local deserializedPos = Vector3.new(unpack(serializedPos))
If you are unfamiliar with the DataStoreService
, you should try to minimize the number of calls to DataStores when you can - so you don’t hit the API limit.
You should load data for deserialization and then initialization, keep a reference to the deserialized data for the server to check against and modify. Whenever you need to save the data, you can serialize it and update the data to the DataStore
So Basically Sterilizing Is Just Saving The Values Of The Part?
Yes sir. It saves the properties to the player’s data. then deserializes it. You may want to consider saving
Then you load all of that, importance is to save the Model Name as that will be your reference for when you need to figure out which model to put where. Store all the models you want in ReplicatedStorage.Assets.Models
as an example. Then just find the Model Name and Clone it!
Yup that’s about it, just sVe avey parts uniquely in dictionary.
I personally use Profile Service to save this data.
Only save when the player leaves the game, and some saves every 5 minutes in case of a server crash.
Save a table to this, you can create custom types if you’d like, and include attributes like the coordinates so your game can quickly retrieve them and place them.
So lets say the player placed a blue cube at -100, 5, -300, but of course that isnt gonna be the same location every time they load presumably, because they may claim a different plot, so find the difference from whatever point you’d like, I like starting at the lowest x, y, and z coordinates so that our new 0,0,0 point in respect to the plot is in a corner. Find this value based on the corner, then save that.
So now Shedletsky has his data as:
PlayerData = {
PlacedBlocks = {
[1] = {
["Name"] = "BlueBlock",
["XYZ"] = Vector3.new(4,1,5),
["Orientation"] = Vector3.new(0,0,0)
}
}
etc. etc.