Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

2 comments

0

Use Coordinates , X , Y , Z not the whole vector3 value

0

Oh, Okay

2 answers

✓ Accepted answer

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

1 comment

0

Oh, I understand, Thanks man

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

2 comments

0

I am not sure if I will use ToString, I tried it last time and my game hung up

0

Yeah tostring doesn' work with any values like vector3 or color3.

This discussion is preserved as it was. New answers, comments, and votes are closed.