Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

[SOLVED]Why does this script make more than twice as much parts?

Asked by 4 years ago
Edited 4 years ago

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)
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. SteelMettle1 394 — 4y
0
so what do i do ? jdm4llfem8 94 — 4y
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. SteelMettle1 394 — 4y
0
tysm jdm4llfem8 94 — 4y

Answer this question