Hello Developers, I’m currently having a really bad time trying to save some Tables.
I’m basically trying to save some coins which have some properties (xp, level, nicknames, isEquipped).
If I have only one Coin in my inventory, everything will work & save fine.
However, if I have 2 Coins in my inventory, I will get a 104 Error (Cannot store Dictionary in data store. Data stores can only accept valid UTF-8 characters.)
If I try to save the same coin 2 times, it will work just fine.
Here’s the code:
local Data = {
Inventory = {
Coins = {};
}:
};
for _, Item in pairs(Player.Inventory.Coins:GetChildren()) do
local ResultEquipped
if Player.ItemEquipped.Value == Item then
ResultEquipped = true
warn(ResultEquipped)
else
ResultEquipped = false
warn(ResultEquipped)
end
local DataToInsert = {
Id = Item.Name;
Xp = Item.Xp.Value;
Level = Item.Level.Value;
Nickname = Item.Nickname.Value;
Equipped = ResultEquipped;
};
table.insert(Data.Inventory.Coins, DataToInsert)
end
local success, errMsg = pcall(function()
PlayerData:SetAsync(Data, UserId)
end)
It’s saving only booleans, numbers and strings, nothing else.
There isn’t too much stuff about it, idk what’s really causing it because as I said if I will add the same table like 2 times, everything will work fine, but if I add a different table it will just crash.
You can’t save Vectors,Rays,Instance (etc)
You only can store Numbers,booleans,strings and tables.
Saving the position
local http = game:GetService("HttpService")
local part = workspace.Part
local datastoreservice = game:GetService("DataStoreService")
local datastore = datastoreservice:GetDataStore("ObjectPosition")
local pos_x = part.Position.X
local pos_y = part.Position.Y
local pos_z = part.Position.Z
local objectTable = {Position = {X = x, Y = y, Z = z}}
objectTable = http:JSONEncode(objectTable)
datastore:UpdateAsync("table",function(oldValue)
return objectTable
end)
Getting the position
local http = game:GetService("HttpService")
local datastoreservice = game:GetService("DataStoreService")
local datastore = datastoreservice:GetDataStore("ObjectPosition")
local part = Instance.new("Part")
part.Parent = workspace
local data = datastore:GetAsync("table")
if not data then return end
data = http:JSONDecode(data)
local position = Vector3.new(data.Position.X,data.Position.Y,data.Position.Z)
part.Position = position
Thats what i said, re-read the post.
Datastore only saves Numbers, strings, booleans and tables.
if you want to saving an instance or ray or vector then you have to serialize it.