I have a minor issue with datastores: every time I save them, the props have an additional array instead of it just being the props name.
My question is: how do I name a table as a variable or something like that? I think this is largely just a syntax issue.
local function SerializeProp(prop)
return {
[prop.Name] = {
prop:GetPivot():GetComponents()
}
}
end
local myProps = {}
for _, prop in testFolder:GetChildren() do
local propName = prop.Name
print(SerializeProp(prop))
table.insert(myProps, SerializeProp(prop))
end
sessionData[player.UserId]["PropData"]["SaveFile1"] = myProps
local function SerializeProp(prop)
return {
prop:GetPivot():GetComponents()
}
end
local myProps = {}
for _, prop in testFolder:GetChildren() do
local propName = prop.Name
print(SerializeProp(prop))
myProps[propName] = SerializeProp(prop)
end
sessionData[player.UserId]["PropData"]["SaveFile1"] = myProps
This data is in line with how your SerializeProp function was designed to work. It is expressing a dictionary that maps the name of the given prop to an array of its CFrame’s components. Is that not what you wanted? Are you sure you’re not misinterpreting what the DataStore Editor is telling you?
Please double check that this reads-back the same value you put in, since DataStores have extra limitations on what can be stored. In particular you can’t have a table indexed by both numbers and strings/userdata, which Lua normally allows.