Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Cannot store Dictionary in data store?

Asked by 3 years ago
Edited 3 years ago

So I made a placement system and you can change its color, material etc. But the only thing that doesnt work is saving the build. here is my script:

local partTable = {}

for i, inst in pairs(workspace:GetChildren()) do
    if inst.Name == "BuiltBlock" then
        local position = inst.Position
        local material = inst.Material
        local color = inst.BrickColor
        local size = inst.Size
        partTable[i] = {Position = position, Material = material, Color = color, Size = size}
    end
end

local success, err = pcall(function()
    BuildsDataStore:SetAsync(player.UserId, partTable)
end)
if err then
   print(err)
end

So when i try to save it, it prints: 104: Cannot store Dictionary in data store. Data stores can only accept valid UTF-8 characters.

Please help!!

Edit: Ok, so I found a way to save the data. But, it saves all the values as one? What is happening here?

0
You can't store Color3 or Vector3 (not sure about material), you can convert those values to ints before saving Leamir 3138 — 3y
0
how would i convert vector3 to an int val DragonSpawner12 61 — 3y
0
convert it to a strings instead, for your case strings would be easier, use JSon greatneil80 2647 — 3y
0
Vector3.X, Vector3.Y, Vector3.Z Leamir 3138 — 3y
View all comments (3 more)
0
ok it doesnt work when i load the build. apparently when i save the table, it takes all the values and adds them all up? why is that? DragonSpawner12 61 — 3y
0
I need to see the save script Leamir 3138 — 3y

1 answer

Log in to vote
1
Answered by 3 years ago

The issue isn't actually the dictionary- it's the contents. DataStores are effectively JSON tables, so they can only store numbers, booleans, tables, and strings. You could fairly easily store the Vector3s and Color3s as arrays/dictionaries like

local vector3 = {
    X = myVector3.X,
    Y = myVector3.Y,
    Z = myVector3.Z
}

local color3 = {
    R = myColor3.R,
    G = myColor3.G,
    B = myColor3.B
}

If you found this answer helpful, do mark it as one.

0
It kind of works, but when i load the build, it prints X cannot be assigned to [blank]. What is happening here? DragonSpawner12 61 — 3y
Ad

Answer this question