ive been trying to make a datasave to save a model, and while it does work, it makes more than 5 times of the part counts. why?

local datasave = game:GetService("DataStoreService")
game.Workspace.RemoteEvent.OnServerEvent:Connect(function(plr,model)
	local parts = {}
	local pos = {}
	local props = {}

    for i,v in pairs(model:GetDescendants()) do
	if v:IsA("BasePart") then
	table.insert(
		props,
		{
			["Color"] = v.BrickColor.Name;
			["Rotation"] = v.Rotation;
			["Anchored"] = v.Anchored;
			}
	)
	table.insert(pos,v.Position)
	v:Destroy()
	end	
end
for _,m in pairs(parts) do
    print(m)
end
for _,f in pairs(pos) do
    print(f)
end
wait(1)
for i,v in pairs(props) do
	for _,m in pairs(pos) do
		local e = Instance.new("Part")
	e.Parent = model
	e.Position = m
	e.BrickColor = BrickColor.new(v.Color)
	e.Rotation = v.Rotation
	e.Anchored = v.Anchored
	end
	end
end)

4 comments

0

I think it's the double for loop on the bottom. What that will do is iterate through the entire contents of the pos table each time there is an entry in the props table.

0

so what do i do ?

0

If you're just saving the position of that prop, then you don't need another whole table. Instead add another key named ["Pos"] within the props table. Then manipulate it exactly how you did with the other attributes of the part by iterating through the props table, only.

0

tysm