How to rotate parts in a plot when loading

if u dont understand here are 2 images


as u can see the 1st image is me making something in a plot, and the 2nd image is me loading ( i added a save and load system ) it in another plot, which is rotated 90 degrees but the structure when loading is not rotated like the plot, it should be facing me not east. how would i do like rotating as the plot heres the script:

local DataStoreService = game:GetService("DataStoreService")
local PlotDataStore = DataStoreService:GetDataStore("PlotSaves")
local CollectionService = game:GetService("CollectionService")

local BLOCK_SIZE = 4

local function getPlotOrigin(plot)
	return plot.PrimaryPart and plot.PrimaryPart.Position or Vector3.new(0, 0, 0)
end

local function getRelativePosition(block, origin)
	local relativePos = (block.Position - origin) / BLOCK_SIZE
	return {relativePos.X, relativePos.Y, relativePos.Z}
end

local function getAbsolutePosition(relativePos, targetOrigin)
	return Vector3.new(relativePos[1], relativePos[2], relativePos[3]) * BLOCK_SIZE + targetOrigin
end

local function savePlot(player, number)
	local plot = player.Claimed.PlotValue.Value
	if not plot or not plot:IsA("Model") then return end

	local origin = getPlotOrigin(plot)
	local blocks = {}

	for _, block in ipairs(plot.BlocksInPlot:GetChildren()) do
		if block:IsA("Part") and not CollectionService:HasTag(block, "PlotGround") then
			table.insert(blocks, {
				getRelativePosition(block, origin),
				{block.Color.R, block.Color.G, block.Color.B}
			})
		end
	end

	local success, err = pcall(function()
		PlotDataStore:SetAsync(player.UserId, {blocks, {origin.X, origin.Y, origin.Z}})
	end)

	game.ReplicatedStorage.Notification:FireClient(player, "Save Successful", "Your build has been saved")

	if success then
		print("Plot saved for", player.Name)
	else
		warn("Failed to save plot:", err)
	end
end

local function loadPlot(player, number, rotation)
	local plot = player.Claimed.PlotValue.Value
	if not plot or not plot:IsA("Model") then return end

	for _, obj in ipairs(plot.BlocksInPlot:GetChildren()) do
		if obj:IsA("Part") and not CollectionService:HasTag(obj, "PlotGround") then
			obj:Destroy()
		end
	end

	local success, data = pcall(function()
		return PlotDataStore:GetAsync(player.UserId)
	end)

	if success and data and data[1] then
		local targetOrigin = getPlotOrigin(plot)

		for _, blockData in ipairs(data[1]) do
			local relativePos = blockData[1]
			local colorData = blockData[2]

			local newBlock = Instance.new("Part")
			newBlock.Size = Vector3.new(BLOCK_SIZE, BLOCK_SIZE, BLOCK_SIZE)
			newBlock.Position = getAbsolutePosition(relativePos, targetOrigin)
			newBlock.Color = Color3.new(colorData[1], colorData[2], colorData[3])
			newBlock.Parent = plot.BlocksInPlot
			newBlock.Name = "Block"
			newBlock.Anchored = true
		end

		print("Plot loaded for", player.Name)

		game.ReplicatedStorage.Notification:FireClient(player, "Load Successful", "Your build has been loaded")
	else
		warn("Failed to load plot:", data)
	end
end

game.ReplicatedStorage.SaveLoad.OnServerEvent:Connect(function(player, type, number, rotation)
	if player.Claimed.Value == true then
		if type == "load" then
			loadPlot(player, number, rotation or 0)
		elseif type == "save" then
			savePlot(player, number)
		end
	end
end)

1 Like

You probably need to read up on the CFrames.

1 Like

ik cframes but like how would i make it all a model ( I CAN DO IT ) and use setprimartypartcframe only for rotation?

BasePart.CFrame or Model:PivotTo()
Model:SetPrimaryPartCFrame is deprecated.

I would just save and load relative CFrame for each block. The script already saves the position but you want the rotation too, just complete it to do what you need. Handling the rotation separately elsewhere seems like an unnecessary complication. I guess if you want to save storage space it’s enough to grab CFrame.Rotation of any one block, since they all have the same rotation anyway.

i dont want to rotate each block singularly