Hello, I am needing help on how to achieve my goal. My goal is to figure out how to save previous values in a DataStore and new values in the same DataStore (Key). Here is what I have in mind so far:
local DataStore = game:GetService("DataStoreService"):GetDataStore("FurniturePositions")
DataStore:SetAsync("HOUSE001", {
-- someway to include old values here?? (or get old values from this key)
Lamp = Vector3.new(0,0,0) -- new value
})
This isn’t entirely what I’m wanting. Basically everytime a player places down an object (Lamp for example) it will save its position and the name of the object in a DataStore and then whenever a player enters their house it will get all of the objects placed/saved in the building and clone them and position them to the objects saved position (Vector3). Therefore I am needing to add onto the old values incase their is previous objects added and add onto them for new objects in this scenario.
From using that above this reply I have come up with this:
if PropertyStore:GetAsync("HOUSE001") then
local old = PropertyStore:GetAsync("HOUSE001")
PropertyStore:SetAsync("HOUSE001", {
table.unpack(old),
[objectName] = objectPos
})
else
PropertyStore:SetAsync("HOUSE001", {
[objectName] = objectPos
})
end
I’m essentially wanting to add-onto the DataStore, so include the old values into the SetAsync(). So it will have the old objects names and positions as well as the new object names and position into the DataStore. So I’m hoping for an output of something like this:
{
["Lamp"] = x,y,z -- old value
["Chair"] = x,y,z -- new value which I just added (somehow)
}
So if I understood correctly, you should have something like that :
local HouseFurnitures = PropertyStore:GetAsync("HOUSE001") or {}
HouseFurnitures["FurnitureName"] = position --with your position converted into a string tho
PropertyStore:SetAsync("HOUSE001", HouseFurnitures)
local PropertyStore = game:GetService('DataStoreService'):GetDataStore("PropertyFurnitureSaveNEWSave")
if PropertyStore:GetAsync("HOUSE001") then
for i,v in pairs(PropertyStore:GetAsync("HOUSE001")) do
print(v)
end
else
warn("Cannot find Data for this House")
end
But I get an output of the position (I would assume):
and what’s the issue here? btw that’s a CFrame so that includes the rotation and also use a variable for PropertyStore:GetAsync(“HOUSE001”) to don’t do useless requests to your datastore, and you should check out profile service bc it’s rlly cool and usefull and makes things easier