Extra dictionary when returning table

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

(this is not all the code)

Like this?

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
2 Likes

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?

Thank you! It works! I’m terrible with tables.

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.

I uh… believe it works? I’m not 100% sure on the lingo. Nothing seems to be wrong when I print out the data.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.