Help on creating a plot save system

Hello everyone! This is my first post here!
So let’s get into the topic! So I tried to create a plotsave system, but it doesn’t save. I even enabled ‘Studio access to API Services’ but it’s still not working. Here’s the code I used:


local PlotSave = game:GetService("DataStoreService"):GetDataStore("PlotSave")

local plots = workspace.Plots

function SavePlot(plr)
     local Data = {}
     local plot = plots[plr.Name.."'s Plot"]
     local savedObjects = plot.savedObjects

    for i, obj in pairs(savedObjects) do
    table.insert(Data, {
["Name"] = obj.Name;

["CFrame"] = {
     ["X"] = obj.PrimaryPart.CFrame.X
     ["Y"] = obj.PrimaryPart.CFrame.Y
     ["Z"] = obj.PrimaryPart.CFrame.Z

}

})
    end

PlotSave:SetAsync(plr.UserId, Data)
end

function LoadPlot(plr)

local Data = {}

Data = PlotSave:GetAsync(plr.UserId, Data)
     for i, obj in pairs(game.ReplicatedStorage.Furniture)do

if Data[1] == obj.Name then
     local clone = obj:Clone()

     clone.Parent = workspace.Plots[plr.Name.."'s Plot"].savedObjects
      
clone.PrimaryPart.CFrame = CFrame.new(Save[2])
end
    
end
end

game.Players.PlayerAdded:Connect(LoadPlot)

game.Players.PlayerRemoving:Connect(SavePlot)

Sorry for the messy code. I had to type this on mobile. If you can help, then please reply.

You are trying to save a dictionary, change it to an array and it should work.

If you struggle that badly you are welcome to look through or use my DSS script

1 Like

Thanks for helping me! I wonder about your dss3 tho. :thinking:

Its just using the fact that datstores use string as the store name and identifier, this means that I can name them numbers and store how many I have, from that number I can get everything saved under one store name. It does mean using the datastore service a second time to get the store count but its worth it for what it can do.

If you dont understand it I wouldnt use it, once you get more advanced into datastores it might be of a bit more use

1 Like

Sorry, but I was looking for someone to help me with that code.

I did tell you the issue, you cant save a dictionary as it is

Sorry, but I’m kind of new to scripting. How do I change it to an array?

So at the moment you have it like this

local Dictionary = {
[“Item1”] = Value1,
[“Item2”] = Value2
}

The [“name”] = value is what makes it a dictionary, meaning when you put thaf name in you get that value back, but datastores dont save this.

Instead do it like this

local array = {Value1,Value2}

Just remember to get what would be item 1 you would do array[1]. Overall, it would be wise to only use arrays as dictionarys are just a pain

Okay, thanks! I hope this works. :smiley:

sorry for the late reply, but only some of this worked, it saved the objects name and cloned it, but when we use arrays, do we use ipairs or pairs in for loops?

Alright, I got it working (finally). I had to loop through the save and index the array stuff.