I’m currently working on a map sharing system, which requires me to store a table of data for every part in the map inside another table. It seems that DataStoreService has issues with storing things like this as it keeps throwing this error at me:
DataStoreService: CantStoreValue: Cannot store Dictionary in data store. Data stores can only accept valid UTF-8 characters. API: SetAsync, Data Store: MapStore v.0
Is JSONEncode a better method that can handle things like this?
Here is my code:
local DataStore = game:GetService("DataStoreService"):GetDataStore("MapStore v.0")
wait(1)
function LoadTrack(track_id)
local data
local success, err = pcall(function()
data = DataStore:GetAsync(track_id)
end)
if err then warn("Data didn't load") end
if not data then print("Track doesn't exist") return end
print(data)
end
function SaveTrack(track_id, mapTable)
print("Saving current track to id "..track_id)
local success, err = pcall(function()
local ds = DataStore:SetAsync(track_id, mapTable)
end)
if err then warn("Data didn't save") end
end
game.ReplicatedStorage.Events.LoadorSaveMap.OnServerEvent:Connect(function(plr, track_id, loadvalue)
if not tonumber(track_id) then warn("ID must be a number!") return end
if loadvalue then LoadTrack(track_id) return end
local TrackTable = {}
for i,part in pairs(workspace.Map:GetChildren()) do
local partInfo = {
Pivot = part:GetPivot(),
Name = part.Name
}
TrackTable[part.Name] = partInfo
end
SaveTrack(track_id, TrackTable)
end)