How would I go about adding a plot saving and loading system to my building game?

I’m making a f3x building game and I want to know how I’d be able to add a plot loading/saving system. I have everything else working however I’m a bit stumped on how I’d be able to accomplish this.

I just don’t know where to start, I’ve looked around but most sources aren’t that helpful, though I think I may have to use serialization?

image

Basically players build in a plot and all their parts are stored inside the “Build” folder. I’m trying to make a system where the player could say something in chat like !Saveplot (Name) to save it, and !Loadplot (Name) to load it.

I’m not asking anyone to write anything for me, I’m just looking for someone to point me in the right direction or possibly link something similar to what I’m looking for.

1 Like

Alright! You’re in luck, I just made this system exactly. So save after the player places, moves, or deletes any of the blocks you save the position of every block
with this

for i,v:Model in ipairs(plot.Value.Buildings:GetChildren()) do
			table.insert(plotdata,{
				["Name"] = v.Name,
				["X"] = plot.Value.CFrame:ToObjectSpace(v.PrimaryPart.CFrame).X,
				["Y"] = plot.Value.CFrame:ToObjectSpace(v.PrimaryPart.CFrame).Y,
				["Z"] = plot.Value.CFrame:ToObjectSpace(v.PrimaryPart.CFrame).Z,
				["RY"] = v.PrimaryPart.Orientation.Y -  plot.Value.Orientation.Y,
			})
		end
		local datamodule = require(	game.ServerScriptService.Scripts.PlayerManager.GetData)
		datamodule.Save("plotdata", plotdata)

so you would get all children of the folder “Build” and then insert the Name, X, Y, Z, and rotation. I only had Y rotation for this but if you want to save all rotation axes then just duplicate and replace with X and Z.

Then I saved it to a module script that does this:

local Module = {}
local data = {}

function Module.Save(name:string,data2)
	if data2 ~= false then
		data[name] = data2
	end	
end

function Module.Get(name)
	return data[name]
end

return Module

So when the player is leaving you would use the get function with the player’s name to get the positions of the plot, you have to save it to a module script because the player-manager script can’t save all the data fast enough before the player leaves.

Then when the player joins you make a script that has a function for placing the blocks or machines. To use the data that was saved you would use this:

local data = datamodule.Get("plotdata")
			local placemachine = game.ServerStorage.BindableEvents.PlaceMachinery
			if data then
				for i,v in ipairs(data) do
					local position = Vector3.new(v["X"],v["Y"],v["Z"])
					placemachine:Fire(player,v["Name"],position,v["RY"])
				end
			end

The bindable event is the function that places the machine.

I hope this helps!!!

mark it as an answer or solution if it helps

2 Likes

You’re a lifesaver!!! Thank you so much!!!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.