Plot saving system

Ive made a game where the player can place items on there plot but im wanting to know how i would make the save so when the players joins back there placed items are the way they left them no matter what plot they choose? Ive looked at on devforum but the topic didn’t make sense

4 Likes

It depends on how you are storing your plot data, if its in a 2D array then you can just save the whole 2D array to the data store. Showing a source of code would help a lot.

I’ve never worked with data stores so i dont know what an array is

Try saving the position of the items when placed in a Vector3 value, then when a player joins, loop through a table of all the items in the game and detect if there is a value inside of it, if so clone the item and place it into the game.

Array is basically a synonym for a table, you construct them with {}.

Yes but i dont really now how i would save that data then recall it on a players entry

myArray = {
“String”,
true,
1
}

for i, v in pairs(myArray) do
print(i)
end

Search up a simple data store tutorial, there’s so many.

I have but i need it to store the position and orientation as a vector 3 value and the tutorials ive viewed haven’t been any help

Set a PrimaryPart of each model and then saving PrimaryPart’s CFrame + other properties.

example of saving:

for i, obj in ipairs(plot.ItemHolder:GetChildren()) do
			table.insert(data, {
				["n"] = obj.Name,
				["x"] =plot.plot.CFrame:ToObjectSpace(CFrame.new(obj.PrimaryPart.CFrame.p)).X,
				["y"] =plot.plot.CFrame:ToObjectSpace(CFrame.new(obj.PrimaryPart.CFrame.p)).Y,
				["z"] =plot.plot.CFrame:ToObjectSpace(CFrame.new(obj.PrimaryPart.CFrame.p)).Z,
				["r1"] =obj.PrimaryPart.Orientation.Y,
				["r2"] =obj.PrimaryPart.Orientation.X,
				["r3"] =obj.PrimaryPart.Orientation.Z
			})
		end

And for loading the model, you do Model:SetPrimaryPartCFrame() and inside you insert all saved properties.

5 Likes

The “plot.plot” is the part on which buildings are placed on.

So im assuming that i would then use datastores to load and save this data?

Yes, that’s how you save any data.

If you need a good DataStore tutorial, i suggest reading this:

So when i would load all the data i would want to loop through all the names and clone back to the players plots item holder?

To have any data be persistent (stores across all servers) you’ll need to make use of DataStores:

Hmm you would clone the model from a folder (that’s we also want to save name), where you store all buildings and then set their PrimaryPart’s CFrame and afterwards inserting into ItemHolder (basically a folder, where all models are being stored for the plot).

As you mentioned because you’re trying to save instances as opposed to just values, you can make use of the following resource:

Hey there MCvojtik,

I find what you wrote very helpful. But there is an issue when loading the models, I used

obj:SetPrimaryPartCFrame(plotpart.CFrame:ToObjectSpace(CFrame.new(v[2],v[3],v[4])))
obj.PrimaryPart.Orientation = Vector3.new(v[5], v[6], v[7])

This worked very well, but the models wouldn’t rotate. Any way I could counter this issue?

Hello,

I have tried the code you have made, however I have not managed to make it work (skill issue on my side), you probably have to load the orientation along the CFrame.

Try following code and let me know whetever the issue will persist.

obj:SetPrimaryPartCFrame(plot.plot.CFrame*CFrame.new(v.x, v.y, v.z)*CFrame.Angles(math.rad(v.r2),math.rad(v.r1), math.rad(v.r3)))

Sincerely, MCvojtik.