103: Array is not allowed in data stores [Solved!]

Okay.

If you want check full script then go here Saving parts/models via datastore? - #33 by Ultraw .
I used script from there as Base for my.

I rewrote your script and i’ve experienced the same error. The variant i made has indentation, which makes it easier to read.

Players = game:GetService("Players")

DataStoreService = game:GetService("DataStoreService")
MyDataStore = DataStoreService:GetDataStore("MyDataStore")

function SavePlace(Player)
	local Models = {}
	local Base = workspace.Slots:FindFirstChild(Player.Name)
	local PrimaryPart_Base = Base.PrimaryPart

	for _, Model in pairs(Base.Items:GetChildren()) do
		local ModelData = {}
		
		local PrimaryPart_Model = Model.PrimaryPart
		local ModelCFrame= PrimaryPart_Model.CFrame * PrimaryPart_Base.CFrame:Inverse()
		
		ModelData.ModelName = Model.Name
		ModelData.ModelCFrame = ModelCFrame
		
		table.insert(Models, ModelData)
	end
	MyDataStore:SetAsync(Player.UserId, Models)
	print("Done!")
end

Players.PlayerRemoving:Connect(SavePlace)

The error i got was:

Cannot store Array in data store. Data stores can only accept valid UTF-8 characters.

2 Likes

So i can’t save table in Data Store?

You can’t store cframes in datastores. Thats why ur getting an error.

1 Like

You mean my script or script by @THEsuperTERROR ?

No, I’m talking in general. Nobody can store CFrames in datastores, unless you “serialize” it.

EDIT: @MrCraeder2005 In case you don’t know how to “serialize” cframes, then I suggest you check out this post:

1 Like

I checked, you indeed can’t store CFrames.
However, you could probably chop up the values it contains into numbers and use that instead.

1 Like

Thank you, i’ll try this method.

1 Like

Also, to answer one of your questions:

Datastore can’t store CFrames. Its kinda like… storing lava in a box, the lava will quite literally burn the box up.

1 Like

What is the difference between Array and Table?

This is a table:

local tbl = {
something = "Idk"
}

This is an array:

local array = {
["Something"] = "Idk... Something. xD"
}

I am not too familiar with tables, and arrays, so the information that I’m giving you might not be correct.

2 Likes

Oh, thanks. I’ll change my script later.

1 Like

{CFrame:components()} is a way of storing cframe but it is HUGE
It is best to round off orientation and position and store those instead
As for other data types, only things like numbers, strings, booleans, nil, arrays, and dictionaries with string keys can be stored. Keep in mind that every character counts!!!
Storing 1000x copies of “0.2032039030240243” is many more characters than “0.2”

2 Likes

Just use tostring() before saving and then later, for getting it, do vector.new(position, position,position)

1 Like

what you can do is create a table of the data you want to be stored and use HttpService:JSONEncode to convert the data to a string and when u want to access the data use HttpService:JSONDecode to convert it back to readable table

1 Like

but data stores already do that, doing it before data stores do it will just increase the character count by 2

I have had a similar issue with trying to store cframes in datastores, and using HttpService:JSONEncode and HttpService:JSONDecode will not work on cframes. (I have tested this out don’t worry :wink: )

all datastore do is take a value and assign it to a variable in a datastore but he wants to store heap data in a data store but he cant do that by putting a table in a datastore so if he converts the table to a string then its valid data and it can be converted back to a table

what kind of data did u give it? can u give an example?

As a suggestion, could you please use punctuation? It makes sentences easier to read. :slight_smile: