I have a datastore that takes specific details about parts in a model and saves them as a dictionary, but to my disappointment I could not store what I had due to an error: cannot store dictionary in datastore, datastores can only accept valid UTF-8 characters.
I read a post with the same problem and they said to “serialize” the information as its appearently too big. but I don’t know how I would do that considering I only used minimal information.
here is the script:
-------------------------------------------------------dats stores--
--------------------------------------------------------------------
local datastore = game:GetService("DataStoreService")
local mydata = datastore:GetDataStore("mydata")
game.Players.PlayerAdded:Connect(function(plr)
local folder = game.ServerScriptService.DataCore:WaitForChild(plr.Name)
local searchtimeout = 50
local buildspace = folder.AssignedBuildSpace
repeat
wait(0.1)
searchtimeout = searchtimeout - 1
until
buildspace.Value ~= nil or searchtimeout <= 0
if not buildspace then
print("no buildspace found for loading")
return
end
local data
local success,fail = pcall(function()
data = mydata:GetAsync(plr.UserId)
end)
if success and data then
--load data------
for _, p in next, data do
wait()
if type(p) == 'table' then
local currentname = p["name"]
local foundpart = game.ReplicatedStorage.BuildingParts:FindFirstChild(currentname)
if foundpart then
local copy = foundpart:Clone()
copy.Parent = buildspace.Value.Parent.Parent.PlayerBuilding
copy.Size = p["size"]
copy.CFrame = buildspace.Value.CFrame:ToWorldSpace(p["cfr"])
copy.BrickColor = p["col"]
end
end
end
-----------------
end
end)
game.Players.PlayerRemoving:Connect(function(plr)
print("saving...")
local folder = game.ServerScriptService.DataCore:WaitForChild(plr.Name)
local data
--model saving code--
local buildspace = folder.AssignedBuildSpace
if not buildspace.Value then
print("no space found for saving")
return
end
local parts = buildspace.Value.Parent.Parent.PlayerBuilding:GetChildren()
local building = {}
local addindex = 1
for i = 1, #parts do
print("loop ran")
if parts[i]:IsA("BasePart") then
print("confirmed basepart")
local currentsurface = buildspace.Value.CFrame:ToObjectSpace(parts[i].CFrame)
print("currentspace is buildspace")
local partinfo = {
name = parts[i].Name;
cfr = currentsurface;
size = parts[i].Size;
col = parts[i].BrickColor
}
print("set part properties")
local indexstring = "partinfo"..addindex
building[indexstring] = partinfo
addindex = addindex + 1
print("added info to building table")
end
end
---------------------
--data to store--
data = building
-----------------
--local success, fail = pcall(function()
mydata:SetAsync(plr.UserId,data)
--end)
--if success then
print("save successful")
--end
end)
---------------------------------------------------------------
---------------------------------------------------------------
a few notes:
SetASync at the bottom has its Pcall turned into a comment in order to see the error come up.
the building dictionary is the model, the partinfo dictionaries are the parts inside the model that are being saved.
partinfo dictionaries only contain basic info such as CFrame, color, name, etc.
why is this happening? and what do I do to fix this?