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 4 years ago
Edited 4 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:

01local partTable = {}
02 
03for i, inst in pairs(workspace:GetChildren()) do
04    if inst.Name == "BuiltBlock" then
05        local position = inst.Position
06        local material = inst.Material
07        local color = inst.BrickColor
08        local size = inst.Size
09        partTable[i] = {Position = position, Material = material, Color = color, Size = size}
10    end
11end
12 
13local success, err = pcall(function()
14    BuildsDataStore:SetAsync(player.UserId, partTable)
15end)
16if err then
17   print(err)
18end

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 — 4y
0
how would i convert vector3 to an int val DragonSpawner12 61 — 4y
0
convert it to a strings instead, for your case strings would be easier, use JSon greatneil80 2647 — 4y
0
Vector3.X, Vector3.Y, Vector3.Z Leamir 3138 — 4y
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 — 4y
0
I need to see the save script Leamir 3138 — 4y

1 answer

Log in to vote
1
Answered by 4 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

01local vector3 = {
02    X = myVector3.X,
03    Y = myVector3.Y,
04    Z = myVector3.Z
05}
06 
07local color3 = {
08    R = myColor3.R,
09    G = myColor3.G,
10    B = myColor3.B
11}

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 — 4y
Ad

Answer this question