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

How do I save a JSON string in a data store?

Asked by 9 years ago

I'm trying to save a JSON string using the following code

print(data)
print("Lengh " .. #data .. " / 65536   " .. math.ceil(#data/655.36) .. "%")
DataStore:SetAsync("SaveData",data)

The result is

{"NickName":"<Nick Name>","Sbucks":0,"ShipParts":[],"Tools":[],"Inventory":{"Coal":3},"Access":5,"Admin":0,"Female":false}
Lengh 122 / 65536   1%
Player -1 leaving
16:45:44.471 - HTTP 500 (HTTP/1.1 500 Internal Server Error)
16:45:44.472 - Script 'ServerScriptService.SurfaceData', Line 87 - global save
16:45:44.473 - Script 'ServerScriptService.SurfaceData', Line 92
16:45:44.473 - Stack End

The resulting string is correct, but it won't save. changing the last line to DataStore:SetAsync("SaveData","Hello") works perfectly, it even loads. Is it because the string it's self has double quotes or something? Should i replace invalid characters with somthing else like single quotes? What exactly can SetAsync handle?

Answer this question