Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Why is this line erroring?

I have a line in my code that is supposed to save a table that is erroring. The error is, "Cannot store Array in Datastore" Here is my script,

game.Players.PlayerAdded:connect(function(plyr)
	while true do
		wait(60)
		local build=script.Parent
		
		local pur=build.purchased
		local DataStore = game:GetService("DataStoreService")
		local PlayerData = DataStore:GetDataStore("PlayerData")
		local PlayerD
		local pnumb=#pur:GetChildren()
		local purs=pur:GetChildren()
		local cframes={}
		local number=0
		for i=1, pnumb do
			number=number+1
			local item=purs[number]
			local cframe=item.PrimaryPart.CFrame
			table.insert(cframes,number,cframe)
			print(item.Name)
			print(cframes[number])
		end
		PlayerData:SetAsync(("OBJECTS".. plyr.UserId),purs)
	end
end)

I have no idea why this is erroring as i thought that tables could be saved with datastore. An explanation could be good.

1 comment

0

ds:SetAsync(key, {v3.x, v3.y, v3.z})

1 answer

You can't store Instances in DataStores. In fact, you can't store any userdata or functions of any description, because they can't be serialized properly (And Roblox hasn't added support for serialization of their own userdata). Part of the reason they can't be serialized properly is likely to be the dependency on JSON format, which has no way of practically distinguishing a serialized userdata from a remarkably similar object.

What you'll have to do instead is serialize every member of purs into its fundamental components/properties, and then instantiate them again when they're loaded using the serialized data as a template.

This discussion is preserved as it was. New answers, comments, and votes are closed.