Need Help Fixing My Plot Save System

Ok, so I made a code and I get a error saying it can’t save the data here is my code:

local DSS = game:GetService(‘DataStoreService’)
local DS = DSS:GetDataStore(‘PlayerData’)
Players = game:GetService(“Players”)

Players.PlayerAdded:Connect(function(Plr)
local Plot = Players.LocalPlayer.Plot
local success, err = pcall(function()
local data = DS:GetAsync(Plr.UserId)
end)
if success then Plot.Value = data[1]
else print(“No data…”)
end
end)

local function Save(Plr)
local DataToSave = { Plr.Plot.Value; }
local success, err = pcall(function()
DS:SetAsync(Plr.UserId, DataToSave)
end)
if not success then
warn(‘Could not save the data’)
end
end

game:BindToClose(function()
for _, Player in pairs(game.Players:GetPlayers()) do
local success, err = pcall(function()
Save(Player)
end)
if success then
print(“Data has been saved”)
else
print(“Data has not been saved!”)
end
end
end)

game.ReplicatedStorage.Events.SetPlot.OnServerEvent:Connect(function(Player, Plot, P)
P.Plot.Value = Plot
Plot.Owner.Value = P
end)

game.Players.PlayerRemoving:Connect(Save)

Have you tried removing ";" from {Plr.Plot.Value}?

what kind of value is Players.LocalPlayer.Plot?

I have tried still did not work

Object Value Inside the player

the semi colon will not affect the compilation of the code as it can be used as a seperator of values in a table, it also wont have an effect if placed at the end of an expression i.e declaring a variable [ abc = 2; ]

1 Like

Data stores dont support storing instances

So how can I make it when someone builds it will load the plots data to the one they select when they load back up

You can do it multiple ways. One way you can do it is you can loop through the plot and save each part / models name and position, and then in server storage or replicated storage when you want to load the plot you can pull the models / parts from it and set their position

Is there a forum I can see an example of this so i think my theory of this would be right.

I’m not exactly sure, but you can probably look for a retail tycoon uncopylocked game and look at the datastore code

Instances can be saved inside datastores through a process called serialization basically you have to convert every property and value of the instance(and its children) into an array, and save the array or the string(using HttpService:JSONEncode(array)) to the datastore.

To deserialize the data you have to reverse the algorithm serializing it.

1 Like

Ok I’ll check it out and get back to you!

Worked, thank you my guy! Finally got it working

1 Like