I am trying to save objects the player has built but I get the error in the title
script in ServerScriptService:
local Data = game:GetService('DataStoreService'):GetDataStore('Data0')
local prefix = 'user_'
game.Players.PlayerAdded:Connect(function(plr)
-- Define variables
local uniquekey = 'id-'..plr.UserId
local Storage = Instance.new("Folder")
Storage.Parent = plr
Storage.Name = "Storage"
local Objects = Storage:GetChildren()
print("Loading boat...")
local function Load()
local plrData = Data:GetAsync(prefix .. tostring(plr.UserId))
if plrData then
Storage:GetChildren(Objects)
Data:SetAsync(uniquekey, Storage)
print("Loaded :D")
else
print("Data wasn't loaded.")
Data:SetAsync(prefix .. tostring(plr.UserId), {
print("Trying again."),
Storage:GetChildren(Objects),
Data:SetAsync(uniquekey, Storage),
print("Loaded")
})
end
end
Load()
end)
game.Players.PlayerRemoving:Connect(function(plr)
print("Saving data for",plr.Name)
Data:GetAsync(prefix .. tostring(plr.UserId))
end)
The problem is at line 22.

11 comments
you can't store instances in datastores (parts, folders, guis etc.) but you can store information about them inside of tables/dictionaries
Then how would I store the objects? Do I make it a child of leaderstats?
if the objects are values just store the values inside a table, then SetAsync(uniquekey, tablename)
Can you give me an example? am really confused
if not just store information about them (position, rotation, size if theyre a part for example) inside the table with their own key
you can look around this tutorial for examples: https://www.robloxdev.com/articles/In-Game-Currency-with-Roblox
They're objects not values...
You can't store objects (instances) in DataStores. Only string and numbers
you don't even save the data when they leave lol
Ik, I tried this:local Objects = {} local get = plr.leaderstats.Storage:GetChildren() local uniquekey = 'id-'..plr.UserId print("Saving data for",plr.Name) for i, v in pairs(get) do table.insert(uniquekey, v.Name) Data:GetAsync(uniquekey, Objects) print("Saved") end, but I get this error:bad argument #1 to 'insert' (table expected, got string)
Because uniquekey is not a table.!