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

i want to save tables, and i made a fairly working script but now i have this error, here’s the script

local Players = game:GetService("Players")

local dataStoreService = game:GetService("DataStoreService")
local dataKey1 = dataStoreService:GetDataStore("PlaceholderSongs3") -- used: 1, 2

Players.PlayerAdded:Connect(function(player)
	
	local boolsFolder = Instance.new("Folder", player)
	boolsFolder.Name = "Bools"
	
	local songsFolder = Instance.new("Folder", boolsFolder)
	songsFolder.Name = "Songs"
	
	local playerkey = "bools_"..player.UserId.."_store"
	dataKey1:GetAsync(playerkey)
	
	local data = dataKey1:GetAsync(playerkey)
	--local data2 = dataKey:GetAsync(equippedPlayerKey)

	print(data)
	
	if data ~= nil then
		for i = 1,#data do
			local V = Instance.new('BoolValue')
			V.Name = data[i][1].Name
			V.Value = data[i][1].Value
			data[i][1] = V
			V.Parent = songsFolder
			for x = 2,#data[1] do
				local V = Instance.new('BoolValue')
				V.Value = data[i][x].Value
				V.Name = data[i][x].Name
				V.Parent = data[i][1]
			end
		end
	end
end)

Players.PlayerRemoving:Connect(function(player)
	
	local songsTable = {}
	
	for i, v in pairs(player.Bools.Songs:GetChildren()) do
		table.insert(songsTable, {v,v.InAlbum,v.placeholder})
			print(songsTable)
			end
	
	local playerkey = "bools_"..player.UserId.."_store"
	 dataKey1:SetAsync(playerkey, songsTable)
end)

In your code you are trying to save the actual bool values to the datastore which isn’t allowed. You can only store basic lua data types in data stores.

How can I save bool values then?

Instead of saving “True” or “False”, try saving things that represent “True” or “False”
Like saving 0 and 1, where 0 represents true and 1 represents false

0 represents false, 1 represents true. True and False are basically the exact same as 1 and 0 respectively, just a friendlier way of displaying and typing it. (There is some under the hood conversion stuff too but that can be a tangent by someone else).

it’s weird that booleans are not allowed in a datastore either.

So do intvalues and if statements?

How would i do that???

Instead of saving the entire instance you can just save the name of the instance and the value it should have. You can then recreate the instances from this data.

The problem stems from this part of your code:

for i, v in pairs(player.Bools.Songs:GetChildren()) do
	table.insert(songsTable, {v,v.InAlbum,v.placeholder}) -- v is an instance (presumably v.InAlbum and v.placeholder are too)
	print(songsTable)
end
	
local playerkey = "bools_"..player.UserId.."_store"
dataKey1:SetAsync(playerkey, songsTable) -- songsTable contains instances so cannot be saved to a datastore
1 Like

Alright, tried that, seems to work, but now how would I recreate the instance on player join

I have this script here:

	if data ~= nil then
		for i = 1,#data do
			local V = Instance.new('BoolValue')
			V.Name = data[i][1].Name
			--V.Value = data[i][1].Value
			data[i][1] = V
			V.Parent = songsFolder
			for x = 2,#data[1] do
				local V = Instance.new('BoolValue')
				--V.Value = data[i][x].Value
				V.Name = data[i][x].Name
				V.Parent = data[i][1]
			end
		end
	end

but when it happens it seems to give me this error here:

Unable to assign property Name. string expected, got nil.

Also how would i save values of the instances

That’s because you’re trying to save an instance here:

The solution is to remove the v in the array

(also yes you can store boolean data please stop making dumb assumptions)

Alright, so how would i save the data without the for i, v?

That’s not what i meant. :man_facepalming:

Im telling you to remove the v in the second parameter of the array in table.insert() function. Like this:

table.insert(songsTable, {v.InAlbum,v.placeholder})

still gives me the error. Here’s the script for now:

local Players = game:GetService("Players")

local dataStoreService = game:GetService("DataStoreService")
local dataKey1 = dataStoreService:GetDataStore("PlaceholderSongs9") -- used: 1, 2, 3, 4, 5, 6, 7 , 8

Players.PlayerAdded:Connect(function(player)
	
	local boolsFolder = Instance.new("Folder", player)
	boolsFolder.Name = "Bools"
	
	local songsFolder = Instance.new("Folder", boolsFolder)
	songsFolder.Name = "Songs"
	
	local playerkey = "bools_"..player.UserId.."_store"
	dataKey1:GetAsync(playerkey)
	
	local data = dataKey1:GetAsync(playerkey)
	--local data2 = dataKey:GetAsync(equippedPlayerKey)

	print(data)
	
	if data ~= nil then
		for i = 1,#data do
			local V = Instance.new('BoolValue')
			V.Name = data[i][1].Name
			V.Value = data[i][1].Value
			data[i][1] = V
			V.Parent = songsFolder
			for x = 2,#data[1] do
				local V = Instance.new('BoolValue')
				V.Value = data[i][x].Value
				V.Name = data[i][x].Name
				V.Parent = data[i][1]
			end
		end
	end
end)

Players.PlayerRemoving:Connect(function(player)
	
	local songsTable = {}
	
	for i, v in pairs(player.Bools.Songs:GetChildren()) do
		table.insert(songsTable, {v.InAlbum,v.placeholder})
			print(songsTable)
			end
	
	local playerkey = "bools_"..player.UserId.."_store"
	 dataKey1:SetAsync(playerkey, songsTable)
end)

Thats because you’re still loading the data like as if it was an instance. With this logic in mind you should re-work entirely how the data is loaded.

It give’s me the error when i leave, not when i join, I also need the second parameter because it’s the name of the first value which is the parent of the other values

Can you please tell me what’s the error? I can’t help you if you don’t tell me the error.

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

The one stated in the title

You there???

It seems that you’re still trying to store an instance by doing v.placeholder and v.InAlbum

Tho what about something like this?

	for i, v in pairs(player.Bools.Songs:GetChildren()) do
		for i, c in pairs(v:GetChildren()) do
		table.insert(songsTable, v, c)
			print(songsTable)
		end
		end

Tho i am not sure how to save the “v” children in the same table, would that work?