So, I'm testing data storing parts through a table library, and since you can't datastore libraries, im going to have to use JSONEncode and Decode right? Well the library has vector3 values in it and it isn't Encoding them. How would I make it so that JSONEncode includes these values? Thanks!
local DataStore = game:GetService('DataStoreService'):GetDataStore('BaseStore') Bases = {} if not DataStore:GetAsync('BaseStore1') then print ("Yes") local AddPart = function() Bases['Part'] = {} Bases.Part['Anchored'] = true Bases.Part['Size'] = Vector3.new(5, 5, 5) Bases.Part['Position'] = CFrame.new (0, 20, 0) end AddPart() else Bases = game:GetService('HttpService'):JSONDecode(DataStore:GetAsync('BaseStore1')) print (game:GetService('HttpService'):JSONDecode(DataStore:GetAsync('BaseStore1'))) for i, v in pairs (Bases.Part) do print (i) end end local Part = Instance.new ('Part') Part.Anchored = Bases.Part.Anchored Part.Size = Bases.Part.Size Part.CFrame = Bases.Part.Position Part.Parent = workspace print (game:GetService'HttpService':JSONEncode(Bases)) DataStore:SetAsync('BaseStore1', game:GetService'HttpService':JSONEncode(Bases))
I haven't really tested these functions, but try them out:
local HttpService = game:GetService("HttpService") local function EncodeVector3(Vector3) --- Encodes a Vector3 in JSON -- @param Vector3 The Vector3 to encode -- @return String The string representation in JSON of the Vector3 value. return HttpService:JSONEncode{ Vector3.x; Vector3.y; Vector3.z; } end local function DecodeVector3(Data) --- decode's a previously encoded Vector3. -- @param Data String of JSON, that was encoded. -- @return Vector3 if it could be decoded, otherwise, nil if Data then local DecodedData = HttpService:JSONDecode(Data) if DecodedData then return Vector3.new(unpack(DecodedData)) end end return nil end local function EncodeCFrame(CFrameValue) --- Encodes a CFrameValue in JSON return HttpService:JSONEncode{CFrameValue:components()} end local function DecodeCFrame(Data) --- decode's a previously encoded CFrameValue. if Data then local DecodedData = HttpService:JSONDecode(Data) if DecodedData then return CFrame.new(unpack(DecodedData)) end end return nil end