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.
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
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?