(Rep+Upvote for thorough answer) I am very interested in data stores and I was planning to save a couple of vectors and load a couple of vectors into a vector3 value called SaveRequest.
So far, my script has no errors but my script isn't working either. It prints everything and it even creates multiple SaveRequests just like I want it to but, I am unsure if I am loading it correctly or saving it correctly since Datastore is my weak topic.
things you should know: The player has a folder called HiddenStats The folder has ItemPos in it The SaveRequests are Vectors that go in ItemPos I use a different way to get the player and it works.
Here is the code:
repeat wait() until game:GetDescendants()
wait(.5)
local DataStore = game:GetService("DataStoreService"):GetDataStore("test")
local lastPos = Vector3.new(0,0,0)
-- getting player
for _, v in pairs(workspace:GetChildren()) do
if v:FindFirstChild("Player") then
local name = v.Player.Value
print(name.." has joined the game :D")
Plr = game.Players:FindFirstChild(name)
end
end
-- fetching data
print("Player Fetched")
print("Fetching data")
local b = 0
repeat b = b + 1
wait()
if Plr then
local inst = Instance.new("Vector3Value", Plr.HiddenStats.ItemPos)
inst.Name = "SaveRequest"..b
DataStore:GetAsync("last"..b)
print("Datastore "..b)
end
until b == 30
print("Loaded everything")
-- setting data
while wait(5) do
print("Setting Data")
local a = 0
if Plr then
for _, v in pairs(Plr.HiddenStats.ItemPos:GetChildren()) do
a = a + 1
print(v.Value)
lastPos = v.Value
DataStore:SetAsync("last"..a,tostring(lastPos))
print("Datastore "..a)
end
else
wait()
end
print("Data has been Set")
end
Thank you for any help!
(Rep + Upvote)

5 comments
So then how can I save it more efficiently??? and make it work because I have a much much much larger script that doesn't work either
I need some examples dude
And by the way I am using ToString to save the vectors
Am I right in saying you are saving all the player's data in seperate keys for example you save the postion in one datastore key and maybe the player name in another?
If you are, you want to structure your save like this Datastore:SetAsync(key,{pos,name,otherdata,moredata}) So then when you load it, you only need 1 load, and when you save it, you only need 1 save.