How would you make a plot of land save in a game?

So me and my friend are developing a simulator where you grow seeds and make a farm. One of the key functions is being able to save your farm plot, so if anyone is willing to take their time and respond I would be grateful.

5 Likes

You would need to utilize datastores for this. I can’t give you a script here since it’s the kind of thing that you can do in a ton of different ways and needs to fit in with the rest of your game.

5 Likes

I believe most games do this by:

  1. Creating a model boundary box, Region3, etc. (basically anything that covers the plot size on a decently large Y-Axis.)

  2. Getting the localspace of each part or center of a model (models would be more efficient) in that area.

  3. Saving the localspace and the part name.

  4. When they rejoin, reference the part or model name and CFrame it to the new plot’s boundary box. (localspace is localspace and doesn’t change with worldspace)

Notes:

  • When using localspace, make sure to assign the localspace + the world space of the boundary box.
  • To get localspace, subtract (boundary box world position - part or model world position)
  • Models would be more efficient and you can get their center by getting the boundary box’s size, dividing that by 2, and adding it to the world space of the boundary box.

Model Boundary Box: Model | Documentation - Roblox Creator Hub

10 Likes

Thanks for responding so quickly!

2 Likes

@snorebear’s solution is good if players can place Parts around the map in ways that you can’t predict. But if your “farm plots” are made up of a regular 2D grid of tiles for example, and there are a limited number of types of plants/plant states, there are more efficient ways of doing it. Depending on your specific case it might not be necessary to optimize though. This whole reply of mine is probably pretty useless :stuck_out_tongue:

For example, a 2D (or any other nD for that matter) grid can be represented as a 1D list. If you have a 100x100 grid, the 2D coordinate of (20, 30) can be represented as a single number i=x + y*width=20+300=320, and the 2D coordinate can be extracted x=i%width, y=math.floor(i/width). That means the position of a plant can be stores with log2(100^2)≈14 bits, while you might need two 32 bit numbers to store the actual X and Y coordinates if you do it naively. You’ll also need to store the plant’s type, and perhaps some state. Depending on the number of types you have you need a few bits, e.g. 8 bits lets you have 256 different plant types. If there are 8 stages of growth you can store that as a 3 bit number.

To actually store e.g. a 14 bit number, use Stravant’s BitBuffer module. The link also has code examples and explanations. Basically it lets you have complete control over the format that your data is stored by turning your raw data into the Base64 format which is basically a string, which is one of the types that DataStore expects.

4 Likes