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

0

you can't store instances in datastores (parts, folders, guis etc.) but you can store information about them inside of tables/dictionaries

0

Then how would I store the objects? Do I make it a child of leaderstats?

0

if the objects are values just store the values inside a table, then SetAsync(uniquekey, tablename)

0

Can you give me an example? am really confused

0

if not just store information about them (position, rotation, size if theyre a part for example) inside the table with their own key

0

you can look around this tutorial for examples: https://www.robloxdev.com/articles/In-Game-Currency-with-Roblox

0

They're objects not values...

0

You can't store objects (instances) in DataStores. Only string and numbers

0

you don't even save the data when they leave lol

0

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)

0

Because uniquekey is not a table.!