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

Why can't I store an 'array' in a DataStore?

Asked by 5 years ago
Edited 5 years ago

I'm making a game that requires saving building information, and I wrote 4 functions that can save the data in tables. However, whenever I try to save it, it says that I "can't save an array in a datastore", even though I'm pretty sure it's a table...? I'm not even sure what the difference between an array and a table is. Any help is appreciated. Here are the functions:

function getData(thing,basepos)

if thing.ClassName == "Model" then

return {thing.PrimaryPart.Position-basepos,thing.PrimaryPart.Orientation,thing.Name}

elseif thing.ClassName == "Part" or thing.ClassName == "MeshPart" or thing.ClassName == "SeatPart" then

return {thing.Position-basepos,thing.Orientation,thing.Name}

end

end



function getAllData(model,basepos)

local alldata = {}

for i = 1, #model:GetChildren() do

local current = model:GetChildren()[i]

local currentData = getData(current,basepos)

alldata[i] = currentData

end

return(alldata)

end



function getModelFromData(data,basepos)

local pos = data[1]

local orientation = data[2]

local name = data[3]

local newModel = game.ReplicatedStorage[name]:Clone()

if newModel.ClassName == "Model" then

newModel:SetPrimaryPartCFrame(CFrame.new(pos,orientation))

elseif newModel.ClassName == "Part" or newModel.ClassName == "SeatPart" or newModel.ClassName == "MeshPart" then

newModel.Position = pos+basepos

newModel.Orientation = orientation

end

return newModel

end



function getModelFromAllData(allData,modelName,basepos)

local thisModel = Instance.new("Model")

thisModel.Name = modelName

for i=1, #allData do

local currentData = allData[i]

local currentmodel = getModelFromData(currentData,basepos)

currentmodel.Parent = thisModel

end

return thisModel

end
0
Is access to external api on? SaltyIceberg 81 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

Sulfone helped me on discord: " a common nickname for a {a, b, c, d, ...} sort of table is 'array' the Vector3s couldn't get saved to the datastore and so it couldn't save that data table "

Ad

Answer this question