Lately, I have been working on a game. It has to save an objects position like one in miners haven... I am making Instances and turning them into Vector 3 Values to save them and so far it is giving me an error saying "Cannot Store Array In DataStore" Can someone help me?
script error..
local DataStore = game:GetService("DataStoreService"):GetDataStore("HelpMePlease") game.Players.PlayerRemoving:connect(function(player) local key = "player-"..player.userId for _, v in pairs(player.HiddenStats.ItemPos:GetChildren()) do print("Saving") valuesToSave = {player.HiddenStats["Item Data Store Name"].Value, v.Value} -- I cannot make this local, It has to be global print(valuesToSave) end DataStore:SetAsync(key, valuesToSave) end end)
the data store error is the DataStore:SetAsync(key, valuesToSave) although it should save.. API is on.
Thanks for any help
So in order to save a Vector3 value you'll have to save it as a table.
local function serializeVector3(vector3) return {vector3.x,vector3.y,vector3.z} end local function deserealizeVector3(serealizedvector3) return Vector3.new(unpack(serealizedvector3) end --example local vector3 = Vector3.new(1,2,3) local vector3holder = serialize(vector3) local unpackvector3 = deserealize(vector3holder) print(unpackvector3) -- Vector3.new(1,2,3) print(vector3holder) -- table: 2F9381DC --saving for i,v in next,DataStore do DataStore["Vector3Value"] = unpackvector3 end
You can do this with any Vector3/Color3/ value. --Credits go to. https://scriptinghelpers.org/questions/51612/how-to-save-a-color3-value
Answer by Radstar1 works, but you can also use the tostring() function and some simple interpolation to translate the text into a vector3 value.