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

How do I fix my building saving script to load properly?

Asked by 4 years ago
Edited 4 years ago
local datastore= game:GetService("DataStoreService")
local store = datastore:GetDataStore("Buildings")
local saveData = "parts"
local save = {}

wait(5)
for i, v in pairs(workspace:GetChildren()) do
    if v:IsA("BasePart") and v.Name ~= "Baseplate" and v.Name ~= "Terrain" then
    table.insert(save, {v.CFrame:GetComponents(),v.Size.X, v.Size.Y, v.Size.Z})    
    end
end
print("saved")
store:SetAsync(saveData, save)

wait(5)
for i, v in pairs(store:GetAsync(saveData)) do
    local part = Instance.new("Part", workspace) 
    print(v)
    part.CFrame = CFrame.new(unpack(v))
    part.Size = Vector3.new(unpack(v))
end
print("loaded")

If I remove the size in both the table and in the load, it loads the CFrame fine. But whenever I try to load the size too, the CFrame errors with:

18:52:12.318 - Invalid number of arguments: 4
18:52:12.318 - Stack Begin
18:52:12.319 - Script 'Workspace.Script', Line 19
18:52:12.319 - Stack End

Answer this question