Hey Roblox devs. I’m making a datastore system in my game, and I came across an issue which I think might be the reason why my data saves haven’t been working. I’m not sure why this error doesn’t show up often when you look it up, but error code 104 looks like this:
"104: Cannot store Dictionary in data store. Data stores can only accept valid UTF-8 characters."
This shouldn’t be a problem with how much data I’m using with the datastore, because I tried using only one value and it still gave me an error. I’ve tried using a module script, which I had no idea how I would solve this with a module, and I’ve tried solving it with all I know of scripting, which is likely why I can’t get ahead.
Can someone explain to me what are the causes of this error? I don’t think I need my script to be fixed, as everything in my script is perfectly fine.
You can only store strings, integers, etc in DataStores.
Roblox DataStores don’t allow instances to be saved, therefore you’re going to have to make a workaround. If you’re trying to save a player (instance), instead of saving them, save their UserId
. Check this article for more information.
My main question is are you saving objects or values? Instances (objects) cannot be saved using DataStores.
Right…I’m storing integers, and also using the player ID already. As I said, there shouldn’t be anything wrong with the script itself. But, I don’t get what you mean by instances. Are you saying if I had like an Instance.new("NumberValue")
it wouldn’t save that?
I’m saving values. Just integers and a folder for leaderstats
You’re trying to save a dictionary with these values, correct? I’d presume so because the error is telling you that it cannot save a dictionary.
I don’t fully know what a dictionary is. Correct me if I’m wrong, it’s like a table right?
1 Like
if it’s a table then yes, I’m using a table. I don’t see how I would work around that though.
Tables are both Arrays and Dictionaries, they can hold multiple datatypes.
They have an “index” and a “value”, when you do something like: table[index]
it’ll give you the value of that index.
Arrays have ordered indexes starting from 1 to how ever many are added, in arrays you do not give the index; instead it gives the index itself.
An array will look like:
local Array = {3, 2, 1}
Loop through this and you’ll see how they’re ordered:
for index, value in pairs(Array) do
print(string.format("%d | %d", index, value))
end
--[[
1 | 3
2 | 2
3 | 1
]]
In Dictionaries you give the index, they’re not ordered.
A Dictionary will look like:
local Dictionary = {
Index1 = 3;
Index2 = 2;
Index3 = 1;
}
Loop through this and you’ll see the specified indexes:
for index, value in pairs(Dictionary) do
print(string.format("%s | %d", index, value))
end
--[[
Index1 | 3
Index2 | 2
Index3 | 1
]]
Dictionaries can also have spaces and non-numeric/non-alphabetic characters in their name though I don’t recommend it, here’s how:
local Dictionary = {
["Hello world"] = true;
["I have spaces"] = true;
["hello?"] = true;
}
It is similar yes. An example:
local sounds = {
["ButtonSound"] = script.Parent:WaitForChild("ButtonSound")
["Music"] = script.Parent:WaitForChild("Music")
}
And they are both arrays and dictionaries (as said in the reply above this one)
You can save tables inside of DataStores, but the issue may be that you have instances inside of your table.
I think I understand…
This is the part of the script that’s causing the issue.
local data = {
Coins = player.leaderstats.Coins;
XP = player.leaderstats.XP;
Level = player.Level;
Rank = player.Rank;
BlackoutLevel = player.GunLevels.BlackoutLevel;
MP7Level = player.GunLevels.MP7Level;
campaignLevel = player.campaignLevel;
CurrentObjective = player.CurrentObjective;
}
I’m assuming all of these instances have a .Value
property which you are not using. You can add a .Value
to the end of each value in the table. You also could have easily mistaken this because they have “Value” at the end of each ClassName.
The items inside the table must be an actual supported datatype for datastores (string, integers, etc).
1 Like
I’d like to assume these are the values. You need to add a .Value
at the end, otherwise it’s trying to save the instance (object)
That fixed it. I remember that I took it away because I was trying to solve another problem, which was the data wasn’t saving on the real game. Thanks though.