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

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

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

2 answers

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

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

0
Oh, I understand, Thanks man greatneil80 2647 — 6y
Ad
Log in to vote
0
Answered by 6 years ago
Edited 6 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 — 6y
0
Yeah tostring doesn' work with any values like vector3 or color3. Radstar1 270 — 6y

Answer this question