I’ll use strings and a decoder.
The DataStore can be anything you want, as long as it has a unique name within your game.
I’m gonna save and load some Vector3s as strings for my example DataStore.
local GPS = game:GetService("DataStoreService"):GetDataStore("GPS")
This DataStore is structured like so, keys are the player’s IDs, and a string is the Vector3. (exampleplayer.UserId,"-1, -1, 0")
local key = tostring(player.UserId)
-- vec3.Value = (-1, -1, 0)
local strig = tostring(vec3.Value) -- Vector3
if key and strig then
GPS:SetAsync(ID,strig) -- Vector3 saved, we don't need :UpdateAsync()
end
Now when I want to load it, that’s the hard part, there’s strategies to do this but I believe it’s down to the ClassNames.
local str = GPS:GetAsync(tostring(player.UserId)) or nil -- getting the player's unique key first
We know that when you tostring(Vector3) x, y, and z are separated by two commas and two spaces.
(-1, -1, 0) Can be broken apart by finding the characters that separate the data!
You can name the strings anything, just have either a method to separate them using special characters or make each name a specific length.
My method of decoding the string for a Vector3 was this function.
local function vec3(str) --- Vec3 decoder, input is string "-1, -1, 0"
local vec = Vector3.new(0,0,0)
local last = string.find(str,",") last-=1
local i = string.sub(str, 1, last)
vec += Vector3.new(tonumber(i),0,0)
str = string.sub(str,last+2,string.len(str))
last = string.find(str,",") last-=1
i = string.sub(str, 1, last)
vec += Vector3.new(0,tonumber(i),0)
str = string.sub(str,last+2,string.len(str))
last = string.len(str)
i = string.sub(str, 1, last)
vec += Vector3.new(0,0,tonumber(i))
return vec -- We get (-1, -1, 0)
end
Make it however you want, go wild. You can do some insane stuff with the sheer amounts of strings a single key can hold. Make sure to use :UpdateAsync() if you’re saving more than one single thing that overwrites!