-
What do you want to achieve? Keep it simple and clear!
I want to make a system where when the player claims a plot, their plants from their last session are back in the same position they left it. -
What is the issue? Include screenshots / videos if possible!
The problem is I don’t know how to do it and make it so that they don’t override each other. I also want the data to update when the plant grows into the next stage. -
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I have tried serialization and looked online but I don’t think they will work for me.
After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
Okay, so you don’t provide anything at all and I don’t want to spoonfeed. Here’s what you need to know:
You need to save the plants in a plot into a table. I assume you already do this. For example:
{ {plant}, {plant} }
. Each plant needs to have it’s position and ofc the data associated with it.
With this table, you now have an effective plot. You can read back this plot by going through the list, getting each plant, and creating a new model or whatever at it’s position. So onto saving.
This is where you’ll need datastore. I personally will point you to a wrapper module like ProfileStore or Datastore2 since I believe it’s easier for the module to deal with the difficult part for you.
Regardless, when a player joins, you load this table from the datastore. You then repopulate the plants into the game world. As the plants grow, you can update the table. Then, periodically and when the player leaves, you set the datastore value to the new table.
Serialization WILL work for you. I run into a lot of problems saving tables into datastores. What I will do is run HTTPService:JsonEncode() on a table and then HTTPService:JsonDecode() to get the table back. JsonEncode turns a table into a string, and decode does the opposite. When saving, save it as a string. When getting it back, take the string and decode it back into the table.
For overrides, if you mean multiple plots, you can do this by attaching a tag after the player. for example,
“IreleventEnstrict-plot1” = {table string}
“IreleventEnstrict-plot2” = {table string}
“IreleventEnstrict-plot3” = {table string}
I posted this on mobile and I was in quite a rush so I didn’t provide much info. Im using profileService right now and The player does have a data table that has their planted crops. I was thinking that once they claim a plot, I can look through my plots folder and find the one they claimed since I change an attribute to their userID and then save all the plants and their positions from that and then load it in once they join and reclaim a plot. Im still on mobile but I will reply later with some concept code to ask if it would work (By overrides I meant like if they have 2 carrots that are in the same stage but in different positions or if it changes stages and I update the data, the other one might get altered).