How do i save multiple arrays an

i want to make a load/save system for multiple parts that are storaged in folder
player can add parts,move them and resize
the issue is the system spawns one part in middle of nowhere
im tried many posts and tutorials but i didnt find answer

local datastore = game:GetService("DataStoreService")
local PltData = datastore:GetDataStore("PltData")
local plrs = nil
local savingtable = {}
game.Players.PlayerAdded:Connect(function(plr)
	plrs = plr
	local data
	local succes,errormsg = pcall(function()
		data = PltData:GetAsync(plr.UserId)
	end)
	if succes and data ~= nil then
		for i,v in pairs(data) do
			local vv = v
			for i = 1, #data, 2 do
				local part = Instance.new("Part")
				part.Parent = game.Workspace.Plot
				part.Anchored = true
				part.Position = Vector3.new(vv.Parent["PosX"],vv.Parent["PosY"],vv.Parent["PosZ"])
				print(data)
			end
			--part.Rotation = Vector3.new(v["RotX"],v["RotY"],v["RotZ"])
			--part.Size = Vector3.new(v["SizeX"],v["SizeY"],v["SizeZ"])
			--part.Color = Color3.fromRGB(v["ColorR"]*225,v["ColorG"]*255,v["ColorB"]*255)
			--part.Material = v["Material"]
			--part.CanCollide = v["CanCollide"]
			--part.Transparency = v["Transparency"]
			--part.Reflectance = v["Reflectance"]
		end
	end
end)
script.SaveEvent.Event:Connect(function()
	table.clear(savingtable)
	for i,v in pairs(game.Workspace.Plot:GetChildren()) do
		local newtable = {PosX = v.Position.X,PosY = v.Position.Y,PosZ = v.Position.Z,SizeX = v.Size.X,SizeY = v.Size.Y,SizeZ = v.Size.Z,ColorR = v.Color.R,ColorG = v.Color.G,ColorB = v.Color.B,Material = v.Material.Name,CanCollide = v.CanCollide,Transparency = v.Transparency,Reflectance = v.Reflectance,RotX = v.Rotation.X,RotY = v.Rotation.Y,RotZ = v.Rotation.Z}
		table.insert(savingtable,newtable)
	end
end)
game.Players.PlayerRemoving:Connect(function()
	print(savingtable)
	PltData:SetAsync(plrs.UserId,savingtable)
end)
--game:BindToClose(function()
--	wait(10)
--end)

I believe the 2 should be a 1, since incrementing it by 2 will skip every other part.

As for the part going in a random position…
You save all the position in a dictionary under PosX, PosY, PosZ, but when accessing them you added .Parent first.
Change the above line to:

part.Position = Vector3.new(vv["PosX"],vv["PosY"],vv["PosZ"])

1 Like

oh i already have fixed it saves and loads fine but i still got issue that when i move the plot the parts doesnt move, i tried many sutff but it were spawning in middle of nowhere

local datastore = game:GetService("DataStoreService")
local PltData = datastore:GetDataStore("PltData")
local plrs = nil
local savingtable = {}
function onPlayerEntered(player)
	player.Chatted:connect(function(msg)
		if msg == "!get" then
			if player.Plot.Value == false then
				print("GOT PLOT")
				local plotpart = game.ReplicatedStorage.Plots.Part:Clone()
				plotpart.Parent = workspace.Plots
				plotpart.Name = player.Name
				plotpart.Position = player.Character.Torso.Position
				local folder = Instance.new("Folder")
				folder.Parent = plotpart
				folder.Name = "content"
				plotpart.Position = Vector3.new(plotpart.Position.X,159,plotpart.Position.Z)
				player.Plot.Value = true
			end
		end
	end)
end

function Loading(player)
	local plr
	plr = player
	local data
	local succes,errormsg = pcall(function()
		data = PltData:GetAsync(plr.UserId)
	end)
	player.Chatted:connect(function(msg)
	if msg == "!load" and player.Plot.Value == true then
			local succes,errormsg = pcall(function()
				data = PltData:GetAsync(plr.UserId)
			end)
			if succes and data ~= nil then
				for i,v in pairs(data) do
					local inst = data[i]
					local part = Instance.new("Part")
					part.Parent = game.Workspace.Plots:WaitForChild(plr.Name).content
					part.Anchored = true
					part.Position = Vector3.new(inst["PosX"],inst["PosY"],inst["PosZ"])
					part.Rotation = Vector3.new(inst["RotX"],inst["RotY"],inst["RotZ"])
					--part.CFrame = part.CFrame * game.Workspace.Plots:WaitForChild(plr.Name).CFrame
					part.Size = Vector3.new(inst["SizeX"],inst["SizeY"],inst["SizeZ"])
					part.Color = Color3.fromRGB(inst["ColorR"]*225,inst["ColorG"]*255,inst["ColorB"]*255)
					part.Material = inst["Material"]
					part.CanCollide = inst["CanCollide"]
					part.Transparency = inst["Transparency"]
					part.Reflectance = inst["Reflectance"]
				end
			end
			print("DONE DONE DONE DONE DONE DONE DONE DONE DONE LOADING")
	end
end)
end

game.Players.PlayerAdded:connect(Loading)

game.Players.PlayerAdded:connect(onPlayerEntered)



function Saving(player)
	player.Chatted:connect(function(msg)
		if msg == "!save" and player.Plot.Value == true then
			table.clear(savingtable)
			for i,v in pairs(game.Workspace.Plots:WaitForChild(player.Name).content:GetChildren()) do
				local newtable = {PosX = v.Position.X,PosY = v.Position.Y,PosZ = v.Position.Z,SizeX = v.Size.X,SizeY = v.Size.Y,SizeZ = v.Size.Z,ColorR = v.Color.R,ColorG = v.Color.G,ColorB = v.Color.B,Material = v.Material.Name,CanCollide = v.CanCollide,Transparency = v.Transparency,Reflectance = v.Reflectance,RotX = v.Rotation.X,RotY = v.Rotation.Y,RotZ = v.Rotation.Z}
				table.insert(savingtable,newtable)
				PltData:SetAsync(player.UserId,savingtable)
				print("DONE DONE DONE DONE DONE DONE DONE DONE DONE SAVING",savingtable)
			end
		end
	end)
end

game.Players.PlayerAdded:connect(Saving)

thank you for answer