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

Data store not saving information because it is a vector 3 value??

Asked by 7 years ago

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..

01local DataStore = game:GetService("DataStoreService"):GetDataStore("HelpMePlease")
02 
03game.Players.PlayerRemoving:connect(function(player)
04    local key = "player-"..player.userId
05    for _, v in pairs(player.HiddenStats.ItemPos:GetChildren()) do
06        print("Saving")
07        valuesToSave = {player.HiddenStats["Item Data Store Name"].Value, v.Value} -- I cannot make this local, It has to be global
08        print(valuesToSave)
09    end
10    DataStore:SetAsync(key, valuesToSave)
11    end
12end)

the data store error is the DataStore:SetAsync(key, valuesToSave) although it should save.. API is on.

Thanks for any help

0
Use Coordinates , X , Y , Z not the whole vector3 value arshad145 392 — 7y
0
Oh, Okay greatneil80 2647 — 7y

2 answers

Log in to vote
1
Answered by
Radstar1 270 Moderation Voter
7 years ago
Edited 7 years ago

So in order to save a Vector3 value you'll have to save it as a table.

01local function serializeVector3(vector3)
02    return {vector3.x,vector3.y,vector3.z}
03end
04local function deserealizeVector3(serealizedvector3)
05    return Vector3.new(unpack(serealizedvector3)
06end
07--example
08local vector3 = Vector3.new(1,2,3)
09 
10local vector3holder = serialize(vector3)
11 
12local unpackvector3 = deserealize(vector3holder)
13print(unpackvector3) -- Vector3.new(1,2,3)
14print(vector3holder) -- table: 2F9381DC
15 
16--saving
17for i,v in next,DataStore do
18    DataStore["Vector3Value"] = unpackvector3
19end

You can do this with any Vector3/Color3/ value. --Credits go to. https://scriptinghelpers.org/questions/51612/how-to-save-a-color3-value

0
Oh, I understand, Thanks man greatneil80 2647 — 7y
Ad
Log in to vote
0
Answered by 7 years ago
Edited 7 years ago

Answer by Radstar1 works, but you can also use the tostring() function and some simple interpolation to translate the text into a vector3 value.

Documentation

0
I am not sure if I will use ToString, I tried it last time and my game hung up greatneil80 2647 — 7y
0
Yeah tostring doesn' work with any values like vector3 or color3. Radstar1 270 — 7y

Answer this question